diff --git a/netforce_clinic/layouts/clinic_account_menu.xml b/netforce_clinic/layouts/clinic_account_menu.xml index 3ee50a7..c6ed01b 100644 --- a/netforce_clinic/layouts/clinic_account_menu.xml +++ b/netforce_clinic/layouts/clinic_account_menu.xml @@ -1,6 +1,6 @@ - + diff --git a/netforce_clinic/layouts/clinic_prod_form.xml b/netforce_clinic/layouts/clinic_prod_form.xml index 5d037ab..9f58722 100644 --- a/netforce_clinic/layouts/clinic_prod_form.xml +++ b/netforce_clinic/layouts/clinic_prod_form.xml @@ -1,8 +1,27 @@ - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/netforce_clinic/models/product.py b/netforce_clinic/models/product.py index 4946d91..235721d 100644 --- a/netforce_clinic/models/product.py +++ b/netforce_clinic/models/product.py @@ -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() diff --git a/netforce_clinic/models/shop.py b/netforce_clinic/models/shop.py index 028d799..d50bb65 100644 --- a/netforce_clinic/models/shop.py +++ b/netforce_clinic/models/shop.py @@ -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',