From a6266c9ae13ea18a5a3df02a695c7182ecbcaac4 Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Fri, 30 Jan 2015 07:37:43 +0700 Subject: [PATCH] if no product in clinic setting, it shold be work too andc credit account will get from account setting -> income account --- netforce_clinic/models/hd_case.py | 33 ++++++++++++++++---------- netforce_clinic/models/hd_case_line.py | 10 +++++++- 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py index fb088d4..1484d32 100644 --- a/netforce_clinic/models/hd_case.py +++ b/netforce_clinic/models/hd_case.py @@ -401,11 +401,14 @@ class HDCase(Model): #account_id=sline.account_id.id account_id=sline.ar_credit_id.id break - # 3.find in product(tab accounting) + # 3.find account in account setting -> income account + if not account_id and not prod: + account_id=setting.income_account_id.id + # 4.find in product(tab accounting) if not account_id: account_id=prod.sale_account_id.id - if not account_id: - raise Exception("Please define sale account for product [%s] %s"%(prod.code, prod.name)) + if not account_id: + raise Exception("Please define sale account for product [%s] %s"%(prod.code, prod.name)) if line.reimbursable=='yes': rmb_lines.append(('create',{ "product_id": prod.id, @@ -980,29 +983,33 @@ class HDCase(Model): vals['lines']=[] for st_prod in st.products: if patient.type_id.id==st_prod.patient_type_id.id: - prod=st_prod.product_id price=st_prod.price qty=st_prod.qty amt=st_prod.amount + categ=st_prod.product_categ_id account_id=st_prod.ar_credit_id.id - if not account_id: - account_id=prod.sale_account_id.id - if not account_id: - raise Exception("Please define sale account for product [%s] %s"%(prod.code, prod.name)) if not amt: amt=qty*price - categ=st_prod.product_categ_id - vals['lines'].append(('create',{ - 'product_id': prod.id, - 'uom_id': st_prod.uom_id.id, + line_vals={ 'product_categ_id': categ.id, + 'uom_id': st_prod.uom_id.id, 'description': st_prod.description, 'price': price, 'qty': qty, 'reimbursable': st_prod.reimbursable, 'amount': amt, 'account_id': account_id, - })) + } + prod=st_prod.product_id + if prod: + line_vals.update({ + 'product_id': prod.id, + }) + if not line_vals['account_id']: + line_vals['account_id']=prod.sale_account_id.id + if not line_vals['account_id']: + raise Exception("Please define sale account for product [%s] %s"%(prod.code, prod.name)) + vals['lines'].append(('create',line_vals)) # XXX need to get default partner=patient.type_id.contact_id if partner: diff --git a/netforce_clinic/models/hd_case_line.py b/netforce_clinic/models/hd_case_line.py index df9d168..bbc5a9e 100644 --- a/netforce_clinic/models/hd_case_line.py +++ b/netforce_clinic/models/hd_case_line.py @@ -1,4 +1,4 @@ -from netforce.model import Model, fields +from netforce.model import Model, fields, get_model class Hdcaseline(Model): _name="clinic.hd.case.line" @@ -18,10 +18,18 @@ class Hdcaseline(Model): "account_id": fields.Many2One("account.account","Account"), } + def _get_categ(self,context={}): + categ_ids=get_model("product.categ").search([['code','=','EPO']]) + if categ_ids: + return categ_ids[0] + else: + return None + _defaults={ 'type': 'others', 'reimbursable': 'no', 'state': 'draft', + 'product_categ_id': _get_categ, } Hdcaseline.register()