product account setting

conv_bal
watcha.h 2015-02-03 14:57:06 +07:00
parent 664ba814c5
commit 7b1a349319
4 changed files with 21 additions and 31 deletions

View File

@ -28,19 +28,6 @@
</field>
</group>
</tab>
<!--
<tab string="RD Shop">
<group span="6" columns="1">
<separator string="Filter Product By Category Below"/>
<field name="shop_categs" noadd="1" nolabel="1">
<list>
<field name="code"/>
<field name="name"/>
</list>
</field>
</group>
</tab>
-->
<tab string="Development">
<button string="Click Me" type="default" method="run_script" perm="clinic_setting_test"/>
</tab>

View File

@ -391,20 +391,17 @@ class HDCase(Model):
if line.amount < 1:
continue #XXX
prod=line.product_id
# 1.find in line
print("#1.find in line")
account_id=line.account_id.id
if not account_id:
# 2.find in clinic setting
for sline in cst.products:
stype=sline.patient_type_id
if stype.id==obj.patient_type_id.id and prod.id==sline.product_id.id:
#account_id=sline.account_id.id
account_id=sline.ar_credit_id.id
break
# 3.find account in account setting -> income account
print("#2.find in ratchawat setting")
prod_acc=cst.get_product_account
acc=prod_acc(prod.id,obj.patient_type_id.id)
account_id=acc.get("ar_credit_id",None)
print("#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)
print("#4.find in product(tab accounting)")
if not account_id:
account_id=prod.sale_account_id.id
if not account_id:
@ -982,12 +979,15 @@ class HDCase(Model):
if not vals.get('lines'):
vals['lines']=[]
for st_prod in st.products:
if patient.type_id.id==st_prod.patient_type_id.id:
ptype=st_prod.patient_type_id
prod=st_prod.product_id
prod_acc=st.get_product_account(prod.id,ptype.id) # get product account
if patient.type_id.id==ptype.id:
price=st_prod.price or 0
qty=st_prod.qty or 0
amt=st_prod.amount
categ=st_prod.product_categ_id
account_id=st_prod.ar_credit_id.id
account_id=prod_acc.get("ar_credit_id",None)
if not amt:
amt=qty*price
line_vals={
@ -1000,7 +1000,6 @@ class HDCase(Model):
'amount': amt,
'account_id': account_id,
}
prod=st_prod.product_id
if prod:
line_vals.update({
'product_id': prod.id,
@ -1008,7 +1007,7 @@ class HDCase(Model):
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))
raise Exception("Please contact accountant: product [%s] %s"%(prod.code, prod.name))
vals['lines'].append(('create',line_vals))
# XXX need to get default
partner=patient.type_id.contact_id

View File

@ -1,6 +1,6 @@
from netforce.model import Model, fields, get_model
from netforce.utils import get_file_path, get_data_path
from netforce.access import get_active_company
from netforce.access import get_active_company, get_active_user
from netforce.database import get_connection
class ClinicSetting(Model):
@ -102,6 +102,10 @@ class ClinicSetting(Model):
return True
def run_script(self,ids,context={}):
user_id=get_active_user
if user_id !=1:
print("Only admin!!")
return
count=1
for hd_case in get_model("clinic.hd.case").search_browse([]):
hd_case.write({
@ -132,12 +136,12 @@ class ClinicSetting(Model):
print("to draft payment ", payment.id)
print("Done")
def get_account_prod(self,ptype_id=None,prod_id=None,context={}):
def get_product_account(self,prod_id=None,patient_type_id=None,context={}):
res={}
for ac_prod in get_model("clinic.setting.account.product").browse([]):
prod=ac_prod.product_id
ptype=ac_prod.patient_type_id
if ptype_id==ptype.id and prod_id==prod.id:
if patient_type_id==ptype.id and prod_id==prod.id:
res.update({
'ar_credit_id': ac_prod.ar_credit_id.id,
'ar_debit_id': ac_prod.ar_debit_id.id,

View File

@ -11,7 +11,7 @@ class SettingAccountProduct(Model):
"patient_type_id": fields.Many2One("clinic.patient.type","Patient Type"),
'categ_id': fields.Many2One("product.categ","Category"),
"product_id": fields.Many2One("product","Product"),
"ar_credit_id": fields.Many2One("account.account","AR Credit",multi_company=True),
"ar_credit_id": fields.Many2One("account.account","Income Credit",multi_company=True),
"ar_debit_id": fields.Many2One("account.account","AR Debit",multi_company=True),
'company_id': fields.Many2One("company","Company"),
}