filter product by 1. categ, 2. code = patient type code

conv_bal
watcha.h 2015-01-26 18:22:18 +07:00
parent dacfa2bded
commit 89b7542ea3
7 changed files with 56 additions and 21 deletions

View File

@ -19,6 +19,7 @@
<field name="req_fee" span="2" invisible="1"/> <field name="req_fee" span="2" invisible="1"/>
<field name="company_id" span="2" invisible="1"/> <!-- to show company name, don't remove --> <field name="company_id" span="2" invisible="1"/> <!-- to show company name, don't remove -->
<field name="hct_include" span="2" invisible="1"/> <field name="hct_include" span="2" invisible="1"/>
<field name="type_code" span="2" invisible="1"/>
</group> </group>
<tabs> <tabs>
<tab string="General"> <tab string="General">
@ -56,8 +57,8 @@
<group span="12" form_layout="stacked"> <group span="12" form_layout="stacked">
<field name="lines" count="3" nolabel="1"> <field name="lines" count="3" nolabel="1">
<list> <list>
<field name="product_id" onchange="onchange_product"/>
<field name="product_categ_id" onchange="onchange_line"/> <field name="product_categ_id" onchange="onchange_line"/>
<field name="product_id" domain='[["categ_id.id","=",product_categ_id],["code","like",parent.type_code]]' onchange="onchange_product"/>
<field name="description"/> <field name="description"/>
<field name="reimbursable" onchange="onchange_line"/> <field name="reimbursable" onchange="onchange_line"/>
<field name="qty" onchange="onchange_line"/> <field name="qty" onchange="onchange_line"/>

View File

@ -11,11 +11,12 @@
<separator string="Expenes"/> <separator string="Expenes"/>
<field name="products" nolabel="1"> <field name="products" nolabel="1">
<list> <list>
<field name="patient_type_id"/> <field name="patient_type_id" onchange="onchange_ptype"/>
<field name="product_id" onchange="onchange_product"/> <field name="type_code" invisible="1"/>
<field name="account_id"/>
<field name="product_categ_id"/> <field name="product_categ_id"/>
<field name="product_id" domain='[["categ_id.id","=",product_categ_id],["code","like",type_code]]' onchange="onchange_product"/>
<field name="description"/> <field name="description"/>
<field name="account_id"/>
<field name="reimbursable"/> <field name="reimbursable"/>
<field name="uom_id"/> <field name="uom_id"/>
<field name="price" onchange="onchange_setting_line"/> <field name="price" onchange="onchange_setting_line"/>
@ -26,7 +27,6 @@
</group> </group>
</tab> </tab>
<tab string="Development"> <tab string="Development">
<!--<field name='branch_id'/>-->
<button string="Click Me" type="default" method="run_script" perm="clinic_setting_test"/> <button string="Click Me" type="default" method="run_script" perm="clinic_setting_test"/>
</tab> </tab>
</tabs> </tabs>

View File

@ -16,11 +16,11 @@
<tab string="General"> <tab string="General">
<field name="lines" nolabel="1"> <field name="lines" nolabel="1">
<list> <list>
<field name="product_id" onchange="onchange_product"/> <field name="product_id" domain='[["categ_id.code","=","EPO"]]' onchange="onchange_product"/>
<field name="description"/> <field name="description"/>
<field name="uom_id"/> <field name="uom_id"/>
<field name="qty"/> <field name="qty" onchange="onchange_line"/>
<field name="price"/> <field name="price" onchange="onchange_line"/>
<field name="amount"/> <field name="amount"/>
</list> </list>
</field> </field>

View File

@ -58,13 +58,17 @@ class HDCase(Model):
res[obj.id]=patient.type_id.id res[obj.id]=patient.type_id.id
return res return res
def _get_hct_include(self,ids,context={}): def _get_store(self,ids,context={}):
res={} res={}
for obj in self.browse(ids): for obj in self.browse(ids):
include=False include=False
type_code=obj.patient_id.type_id.code
if obj.patient_id.type_id.hct_include: if obj.patient_id.type_id.hct_include:
include=True include=True
res[obj.id]=include res[obj.id]={
'hct_include': include,
'type_code': type_code,
}
return res return res
_fields={ _fields={
@ -90,7 +94,8 @@ class HDCase(Model):
"ultrafittration": fields.Float("Ultrafiltration (kg.)"), "ultrafittration": fields.Float("Ultrafiltration (kg.)"),
"hct": fields.Integer("Hct",required=True), "hct": fields.Integer("Hct",required=True),
"hct_msg" : fields.Char(""), "hct_msg" : fields.Char(""),
'hct_include': fields.Boolean("HCT Include", function="_get_hct_include",store=True), 'hct_include': fields.Boolean("HCT Include", function="_get_store", function_multi=True,store=True),
'type_code': fields.Char("Product Code", function="_get_store", function_multi=True,store=True),
"state": fields.Selection([("draft","Draft"),('waiting_treatment','Waiting Treatment'),("in_progress","In Progress"),("completed","Finish Treatment"),('paid','Paid'),("waiting_payment","Waiting Payment"),("discountinued","Discountinued"),("cancelled","Cancelled")],"Status",required=True), "state": fields.Selection([("draft","Draft"),('waiting_treatment','Waiting Treatment'),("in_progress","In Progress"),("completed","Finish Treatment"),('paid','Paid'),("waiting_payment","Waiting Payment"),("discountinued","Discountinued"),("cancelled","Cancelled")],"Status",required=True),
"staffs": fields.One2Many("clinic.hd.case.staff","hd_case_id","Staffs"), "staffs": fields.One2Many("clinic.hd.case.staff","hd_case_id","Staffs"),
"comments": fields.One2Many("message","related_id","Comments"), "company_id": fields.Many2One("company","Company"), "comments": fields.One2Many("message","related_id","Comments"), "company_id": fields.Many2One("company","Company"),
@ -220,6 +225,7 @@ class HDCase(Model):
data['branch_id']=branch.id data['branch_id']=branch.id
data['cycle_id']=cycle.id data['cycle_id']=cycle.id
data['patient_type_id']=patient.type_id.id data['patient_type_id']=patient.type_id.id
data['type_code']=patient.type_id.code
if patient.type_id.hct_include: if patient.type_id.hct_include:
data['hct_include']=True data['hct_include']=True
else: else:

View File

@ -67,6 +67,15 @@ class ClinicSetting(Model):
line['amount']=amt line['amount']=amt
return data return data
def onchange_ptype(self,context={}):
data=context['data']
path=context['path']
line=get_data_path(data,path,parent=True)
ptype_id=line['patient_type_id']
ptype=get_model("clinic.patient.type").browse(ptype_id)
line['type_code']=ptype.code or ''
return data
def onchange_setting_line(self,context={}): def onchange_setting_line(self,context={}):
data=context['data'] data=context['data']
path=context['path'] path=context['path']
@ -91,15 +100,13 @@ class ClinicSetting(Model):
return True return True
def run_script(self,ids,context={}): def run_script(self,ids,context={}):
#db=get_connection() hids=get_model("clinic.hd.case").search([])
#db.execute('update clinic_cycle_item set date_validate=write_time;') get_model('clinic.hd.case').function_store(hids)
dom=[] obj=self.browse(ids)[0]
dom.append(['nurse_id','=',338]) for prod in obj.products:
dom.append(['cycle_item_id.date','>=','2015-01-15']) prod.write({
dom.append(['cycle_item_id.date','<=','2015-01-15']) 'type_code': prod.patient_type_id.code,
for tline in get_model("clinic.cycle.item.line").search_browse(dom): })
item=tline.cycle_item_id
print(item.name)
print("Done! ") print("Done! ")
def reset_last_import(self,ids,context={}): def reset_last_import(self,ids,context={}):

View File

@ -9,6 +9,7 @@ class SettingProduct(Model):
_fields={ _fields={
"setting_id": fields.Many2One("clinic.setting","Setting"), "setting_id": fields.Many2One("clinic.setting","Setting"),
"patient_type_id": fields.Many2One("clinic.patient.type","Patient Type"), "patient_type_id": fields.Many2One("clinic.patient.type","Patient Type"),
'type_code': fields.Char("Code"),
"product_categ_id": fields.Many2One("product.categ","Category",domain=[['expense','=',True]]), "product_categ_id": fields.Many2One("product.categ","Category",domain=[['expense','=',True]]),
'reimbursable': fields.Selection([['yes','Yes'],['no','No']],"Reimbursable"), 'reimbursable': fields.Selection([['yes','Yes'],['no','No']],"Reimbursable"),
'uom_id': fields.Many2One("uom","UOM", required=True), 'uom_id': fields.Many2One("uom","UOM", required=True),

View File

@ -11,8 +11,12 @@ class Shop(Model):
def _get_all(self,ids,context={}): def _get_all(self,ids,context={}):
res={} res={}
for obj in self.browse(ids): for obj in self.browse(ids):
total=0
for line in obj.lines:
amt=line.amount or 0
total+=amt
res[obj.id]={ res[obj.id]={
'total': 0, 'total': total,
} }
return res return res
@ -51,6 +55,21 @@ class Shop(Model):
'state': 'draft', 'state': 'draft',
} }
def update_all(self,context={}):
data=context['data']
data['total']=0
for line in data['lines']:
data['total']+=line['amount'] or 0
return data
def onchange_line(self,context={}):
data=context['data']
path=context['path']
line=get_data_path(data,path,parent=True)
line['amount']=(line['qty'] or 0)*(line['price'] or 0)
data=self.update_all(context=context)
return data
def onchange_product(self,context={}): def onchange_product(self,context={}):
data=context['data'] data=context['data']
path=context['path'] path=context['path']
@ -63,6 +82,7 @@ class Shop(Model):
if not line.get('qty'): if not line.get('qty'):
line['qty']=1 line['qty']=1
line['amount']=line['price']*line['qty'] line['amount']=line['price']*line['qty']
data=self.update_all(context)
return data return data
Shop.register() Shop.register()