post invoice from rd shop
							parent
							
								
									61228c3e1c
								
							
						
					
					
						commit
						387e5a567a
					
				| 
						 | 
				
			
			@ -1,6 +1,6 @@
 | 
			
		|||
<inherit inherit="account_menu">
 | 
			
		||||
    <item string="Settings" position="before">
 | 
			
		||||
        <item string="Ratchawat">
 | 
			
		||||
        <item string="Ratchawat Clinic">
 | 
			
		||||
            <item string="Account Product" action="clinic_setting_account_product"/>
 | 
			
		||||
            <item string="Account Patient" action="clinic_setting_account_patient"/>
 | 
			
		||||
            <item string="HD Case Expense" action="clinic_report_account_hd_case_summary"/>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,8 +1,27 @@
 | 
			
		|||
<inherit model="product" inherit="product_form">
 | 
			
		||||
    <field name="categ_id" position="after">
 | 
			
		||||
        <field name="patient_types"/>
 | 
			
		||||
    </field>
 | 
			
		||||
    <field name="create_time" position="after">
 | 
			
		||||
        <field name="report_visible"/>
 | 
			
		||||
    </field>
 | 
			
		||||
    <tab string="Other" position="after">
 | 
			
		||||
        <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>
 | 
			
		||||
                <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"/>
 | 
			
		||||
            </group>
 | 
			
		||||
        </tab>
 | 
			
		||||
    </tab>
 | 
			
		||||
</inherit>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -6,6 +6,7 @@ class Product(Model):
 | 
			
		|||
        'patient_types': fields.Many2Many("clinic.patient.type","Patient Types"),
 | 
			
		||||
        'departments': fields.One2Many('clinic.department.product','product_id','Departments'),
 | 
			
		||||
        'report_visible': fields.Boolean("Report Visible"),
 | 
			
		||||
        'account_products': fields.One2Many('clinic.setting.account.product','product_id','Account Products'),
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
Product.register()
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -320,22 +320,8 @@ class Shop(Model):
 | 
			
		|||
        prod_acc=cst.get_product_account
 | 
			
		||||
        partner=obj.contact_id
 | 
			
		||||
        context['branch_id']=obj.branch_id.id
 | 
			
		||||
        number=self._get_credit_number(context=context),
 | 
			
		||||
        vals={
 | 
			
		||||
            'number': number,
 | 
			
		||||
            "type": "out",
 | 
			
		||||
            "inv_type": "invoice",
 | 
			
		||||
            "tax_type": "tax_in",
 | 
			
		||||
            'due_date': obj.due_date,
 | 
			
		||||
            "ref": obj.number or "",
 | 
			
		||||
            'department_id': obj.department_id.id,
 | 
			
		||||
            "related_id": "clinic.shop,%s"%obj.id,
 | 
			
		||||
            "currency_id": currency_id,
 | 
			
		||||
            "company_id": company_id,
 | 
			
		||||
            'partner_id': partner.id,
 | 
			
		||||
            "lines": [],
 | 
			
		||||
        }
 | 
			
		||||
        track_id=obj.branch_id.track_id.id
 | 
			
		||||
        inv_lines=[]
 | 
			
		||||
        for line in obj.lines:
 | 
			
		||||
            if line.amount < 1:
 | 
			
		||||
                continue
 | 
			
		||||
| 
						 | 
				
			
			@ -347,7 +333,7 @@ class Shop(Model):
 | 
			
		|||
                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',{
 | 
			
		||||
            inv_lines.append(('create',{
 | 
			
		||||
                    "product_id": prod.id,
 | 
			
		||||
                    "description": line.description or "",
 | 
			
		||||
                    "qty": line.qty,
 | 
			
		||||
| 
						 | 
				
			
			@ -358,9 +344,37 @@ class Shop(Model):
 | 
			
		|||
                    'ar_debit_id': ar_debit_id,
 | 
			
		||||
                    'track_id': track_id,
 | 
			
		||||
                }))
 | 
			
		||||
        inv_id=get_model("account.invoice").create(vals,context=context)
 | 
			
		||||
        inv=get_model("account.invoice").browse(inv_id)
 | 
			
		||||
        inv.post()
 | 
			
		||||
        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),
 | 
			
		||||
            vals={
 | 
			
		||||
                'number': number,
 | 
			
		||||
                "type": "out",
 | 
			
		||||
                "inv_type": "invoice",
 | 
			
		||||
                "tax_type": "tax_in",
 | 
			
		||||
                'due_date': obj.due_date,
 | 
			
		||||
                "ref": obj.number or "",
 | 
			
		||||
                'department_id': obj.department_id.id,
 | 
			
		||||
                "related_id": "clinic.shop,%s"%obj.id,
 | 
			
		||||
                "currency_id": currency_id,
 | 
			
		||||
                "company_id": company_id,
 | 
			
		||||
                'patient_partner_id':partner.id, #to check before post
 | 
			
		||||
                'partner_id': partner.id,
 | 
			
		||||
                "lines": lines,
 | 
			
		||||
                'account_id': account_receiveable_id,
 | 
			
		||||
            }
 | 
			
		||||
            inv_id=get_model("account.invoice").create(vals,context=context)
 | 
			
		||||
            inv=get_model("account.invoice").browse(inv_id)
 | 
			
		||||
            inv.post()
 | 
			
		||||
        obj.make_pickings()
 | 
			
		||||
        obj.write({
 | 
			
		||||
            'state': 'waiting_payment',
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue