post invoice from rd shop
							parent
							
								
									61228c3e1c
								
							
						
					
					
						commit
						387e5a567a
					
				| 
						 | 
					@ -1,6 +1,6 @@
 | 
				
			||||||
<inherit inherit="account_menu">
 | 
					<inherit inherit="account_menu">
 | 
				
			||||||
    <item string="Settings" position="before">
 | 
					    <item string="Settings" position="before">
 | 
				
			||||||
        <item string="Ratchawat">
 | 
					        <item string="Ratchawat Clinic">
 | 
				
			||||||
            <item string="Account Product" action="clinic_setting_account_product"/>
 | 
					            <item string="Account Product" action="clinic_setting_account_product"/>
 | 
				
			||||||
            <item string="Account Patient" action="clinic_setting_account_patient"/>
 | 
					            <item string="Account Patient" action="clinic_setting_account_patient"/>
 | 
				
			||||||
            <item string="HD Case Expense" action="clinic_report_account_hd_case_summary"/>
 | 
					            <item string="HD Case Expense" action="clinic_report_account_hd_case_summary"/>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,8 +1,27 @@
 | 
				
			||||||
<inherit model="product" inherit="product_form">
 | 
					<inherit model="product" inherit="product_form">
 | 
				
			||||||
    <field name="categ_id" position="after">
 | 
					    <tab string="Other" position="after">
 | 
				
			||||||
        <field name="patient_types"/>
 | 
					        <tab string="Ratchawat Clinic">
 | 
				
			||||||
 | 
					            <group form_layout="stacked">
 | 
				
			||||||
 | 
					                <separator string="View Product"/>
 | 
				
			||||||
 | 
					                <field name="patient_types" nolabel="1" span="12">
 | 
				
			||||||
 | 
					                    <list>
 | 
				
			||||||
 | 
					                        <field name="code"/>
 | 
				
			||||||
 | 
					                        <field name="name"/>
 | 
				
			||||||
 | 
					                        <field name="default"/>
 | 
				
			||||||
 | 
					                    </list>
 | 
				
			||||||
                </field>
 | 
					                </field>
 | 
				
			||||||
    <field name="create_time" position="after">
 | 
					                <separator string="Account Product Setting"/>
 | 
				
			||||||
 | 
					                <field name="account_products" nolabel="1">
 | 
				
			||||||
 | 
					                    <list>
 | 
				
			||||||
 | 
					                        <field name="patient_type_id"/>
 | 
				
			||||||
 | 
					                        <field name="ar_debit_id"/>
 | 
				
			||||||
 | 
					                        <field name="ar_credit_id"/>
 | 
				
			||||||
 | 
					                        <field name="type"/>
 | 
				
			||||||
 | 
					                    </list>
 | 
				
			||||||
 | 
					                </field>
 | 
				
			||||||
 | 
					                <separator string="Report HD Case Summary Setting"/>
 | 
				
			||||||
                <field name="report_visible"/>
 | 
					                <field name="report_visible"/>
 | 
				
			||||||
    </field>
 | 
					            </group>
 | 
				
			||||||
 | 
					        </tab>
 | 
				
			||||||
 | 
					    </tab>
 | 
				
			||||||
</inherit>
 | 
					</inherit>
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -6,6 +6,7 @@ class Product(Model):
 | 
				
			||||||
        'patient_types': fields.Many2Many("clinic.patient.type","Patient Types"),
 | 
					        'patient_types': fields.Many2Many("clinic.patient.type","Patient Types"),
 | 
				
			||||||
        'departments': fields.One2Many('clinic.department.product','product_id','Departments'),
 | 
					        'departments': fields.One2Many('clinic.department.product','product_id','Departments'),
 | 
				
			||||||
        'report_visible': fields.Boolean("Report Visible"),
 | 
					        'report_visible': fields.Boolean("Report Visible"),
 | 
				
			||||||
 | 
					        'account_products': fields.One2Many('clinic.setting.account.product','product_id','Account Products'),
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Product.register()
 | 
					Product.register()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -320,6 +320,41 @@ class Shop(Model):
 | 
				
			||||||
        prod_acc=cst.get_product_account
 | 
					        prod_acc=cst.get_product_account
 | 
				
			||||||
        partner=obj.contact_id
 | 
					        partner=obj.contact_id
 | 
				
			||||||
        context['branch_id']=obj.branch_id.id
 | 
					        context['branch_id']=obj.branch_id.id
 | 
				
			||||||
 | 
					        track_id=obj.branch_id.track_id.id
 | 
				
			||||||
 | 
					        inv_lines=[]
 | 
				
			||||||
 | 
					        for line in obj.lines:
 | 
				
			||||||
 | 
					            if line.amount < 1:
 | 
				
			||||||
 | 
					                continue
 | 
				
			||||||
 | 
					            prod=line.product_id
 | 
				
			||||||
 | 
					            acc=prod_acc(prod.id,shop_type.id,'credit')
 | 
				
			||||||
 | 
					            account_id=acc.get("ar_credit_id",None)
 | 
				
			||||||
 | 
					            ar_debit_id=acc.get("ar_debit_id",None)
 | 
				
			||||||
 | 
					            if not account_id:
 | 
				
			||||||
 | 
					                raise Exception("No Income Credit Account for product [%s] %s"%(prod.code, prod.name))
 | 
				
			||||||
 | 
					            if not ar_debit_id:
 | 
				
			||||||
 | 
					                raise Exception("No Ar Debit Account for product [%s] %s"%(prod.code, prod.name))
 | 
				
			||||||
 | 
					            inv_lines.append(('create',{
 | 
				
			||||||
 | 
					                    "product_id": prod.id,
 | 
				
			||||||
 | 
					                    "description": line.description or "",
 | 
				
			||||||
 | 
					                    "qty": line.qty,
 | 
				
			||||||
 | 
					                    "uom_id": line.uom_id.id,
 | 
				
			||||||
 | 
					                    "unit_price": line.price or 0,
 | 
				
			||||||
 | 
					                    "amount": line.amount or 0,
 | 
				
			||||||
 | 
					                    'account_id': account_id,
 | 
				
			||||||
 | 
					                    'ar_debit_id': ar_debit_id,
 | 
				
			||||||
 | 
					                    'track_id': track_id,
 | 
				
			||||||
 | 
					                }))
 | 
				
			||||||
 | 
					        def group_invoice_line(invoice_lines):
 | 
				
			||||||
 | 
					            invoice_vals={}
 | 
				
			||||||
 | 
					            for mode,invoice_line in invoice_lines:
 | 
				
			||||||
 | 
					                ar_debit_id=invoice_line['ar_debit_id']
 | 
				
			||||||
 | 
					                if not invoice_vals.get(ar_debit_id):
 | 
				
			||||||
 | 
					                    invoice_vals[ar_debit_id]=[]
 | 
				
			||||||
 | 
					                del invoice_line['ar_debit_id']
 | 
				
			||||||
 | 
					                invoice_vals[ar_debit_id].append((mode,invoice_line))
 | 
				
			||||||
 | 
					            return invoice_vals
 | 
				
			||||||
 | 
					        invoices=group_invoice_line(inv_lines)
 | 
				
			||||||
 | 
					        for account_receiveable_id, lines in invoices.items():
 | 
				
			||||||
            number=self._get_credit_number(context=context),
 | 
					            number=self._get_credit_number(context=context),
 | 
				
			||||||
            vals={
 | 
					            vals={
 | 
				
			||||||
                'number': number,
 | 
					                'number': number,
 | 
				
			||||||
| 
						 | 
					@ -332,32 +367,11 @@ class Shop(Model):
 | 
				
			||||||
                "related_id": "clinic.shop,%s"%obj.id,
 | 
					                "related_id": "clinic.shop,%s"%obj.id,
 | 
				
			||||||
                "currency_id": currency_id,
 | 
					                "currency_id": currency_id,
 | 
				
			||||||
                "company_id": company_id,
 | 
					                "company_id": company_id,
 | 
				
			||||||
 | 
					                'patient_partner_id':partner.id, #to check before post
 | 
				
			||||||
                'partner_id': partner.id,
 | 
					                'partner_id': partner.id,
 | 
				
			||||||
            "lines": [],
 | 
					                "lines": lines,
 | 
				
			||||||
 | 
					                'account_id': account_receiveable_id,
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        track_id=obj.branch_id.track_id.id
 | 
					 | 
				
			||||||
        for line in obj.lines:
 | 
					 | 
				
			||||||
            if line.amount < 1:
 | 
					 | 
				
			||||||
                continue
 | 
					 | 
				
			||||||
            prod=line.product_id
 | 
					 | 
				
			||||||
            acc=prod_acc(prod.id,shop_type.id,'credit')
 | 
					 | 
				
			||||||
            account_id=acc.get("ar_credit_id",None)
 | 
					 | 
				
			||||||
            ar_debit_id=acc.get("ar_debit_id",None)
 | 
					 | 
				
			||||||
            if not account_id:
 | 
					 | 
				
			||||||
                raise Exception("No Income Credit Account for product [%s] %s"%(prod.code, prod.name))
 | 
					 | 
				
			||||||
            if not ar_debit_id:
 | 
					 | 
				
			||||||
                raise Exception("No Ar Debit Account for product [%s] %s"%(prod.code, prod.name))
 | 
					 | 
				
			||||||
            vals['lines'].append(('create',{
 | 
					 | 
				
			||||||
                    "product_id": prod.id,
 | 
					 | 
				
			||||||
                    "description": line.description or "",
 | 
					 | 
				
			||||||
                    "qty": line.qty,
 | 
					 | 
				
			||||||
                    "uom_id": line.uom_id.id,
 | 
					 | 
				
			||||||
                    "unit_price": line.price or 0,
 | 
					 | 
				
			||||||
                    "amount": line.amount or 0,
 | 
					 | 
				
			||||||
                    'account_id': account_id,
 | 
					 | 
				
			||||||
                    'ar_debit_id': ar_debit_id,
 | 
					 | 
				
			||||||
                    'track_id': track_id,
 | 
					 | 
				
			||||||
                }))
 | 
					 | 
				
			||||||
            inv_id=get_model("account.invoice").create(vals,context=context)
 | 
					            inv_id=get_model("account.invoice").create(vals,context=context)
 | 
				
			||||||
            inv=get_model("account.invoice").browse(inv_id)
 | 
					            inv=get_model("account.invoice").browse(inv_id)
 | 
				
			||||||
            inv.post()
 | 
					            inv.post()
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue