conv_bal
watcha.h 2014-10-02 22:26:14 +07:00
parent 49aa5d555d
commit 31f10ca9c2
5 changed files with 103 additions and 13 deletions

View File

@ -2,7 +2,7 @@
<field name="string">Dialyzer</field>
<field name="view_cls">multi_view</field>
<field name="model">clinic.dialyzer</field>
<field name="tabs">[["All",[]],["Draft",[["state","=","draft"]]],["Active",[["state","=","active"]]],["Drop",[["state","=","drop"]]]]</field>
<field name="modes">list,page,form</field>
<field name="tabs">[["All",[]],["New",[["state","=","new"]]],["Active",[["state","=","active"]]],["Drop",[["state","=","drop"]]],["Cancelled",[["state","=","cancelled"]]]]</field>
<field name="modes">list,page,form</field>
<field name="menu">clinic_menu</field>
</action>

View File

@ -1,8 +1,8 @@
<form model="clinic.dialyzer">
<form model="clinic.dialyzer" attrs='{"readonly":[["state","in",["cancelled","drop","active"]]]}' show_company="1">
<head>
<field name="state"/>
<button string="Options" dropdown="1">
<item string="Drop"/>
<item string="Copy" method="copy"/>
</button>
</head>
<group span="6" columns="1">
@ -16,13 +16,16 @@
<group span="6" columns="1">
<field name="product_id"/>
<field name="dialyzer_type"/>
<field name="use_time"/>
<field name="use_time" readonly="1"/>
<field name="max_use_time"/>
<field name="exp_date"/>
<field name="description"/>
</group>
<foot>
<button string="Confirm" type="success" method="confirm"/>
<button string="Confirm" type="success" states="new" method="confirm"/>
<button string="Drop" type="danger" states="active" method="drop"/>
<button string="Cancel" type="default" states="active" method="cancel"/>
<button string="Renew" type="success" states="cancelled" method="renew"/>
</foot>
<related>
<field name="pickings" click_action="view_picking"/>

View File

@ -2,6 +2,7 @@
<item string="Dashboard" action="clinic_board"/>
<item string="Visits" action="clinic_visit"/>
<item string="Treatments" action="clinic_hd_case"/>
<item string="Dialyzer" action="clinic_dialyzer"/>
<item string="Personal">
<item string="Doctors" action="clinic_doctor"/>
<item string="Nurses" action="clinic_nurse"/>
@ -14,7 +15,6 @@
<item string="Account (TB, Unpaid AP and AR)" action="report1"/>
</item>
<item string="Settings">
<item string="Dialyzer" action="clinic_dialyzer"/>
<item string="Departments" action="clinic_department"/>
<item string="Graduations" action="clinic_grade"/>
<item string="Nationalities" action="clinic_nation"/>

View File

@ -41,6 +41,20 @@ class Dialyzer(Model):
if not res:
return num
get_model("sequence").increment_number(seq_id,context=context)
def _get_product(self,context={}):
categ_ids=get_model("product.categ").search([['name','=','Dialyzer']])
product_id=None
stop=False
for prod in get_model("product").search_browse([]):
if stop:
break
for categ in prod.categs:
if categ.id in categ_ids:
product_id=prod.id
stop=True
break
return product_id
_defaults={
"state": "new",
@ -49,7 +63,7 @@ class Dialyzer(Model):
"max_use_time": 10,
"use_time": 0,
"company_id": lambda *a: get_active_company(),
'product_id': 48, # TODO search product with categ name is "Dialyzer"
'product_id': _get_product,
}
_order="date desc,number desc"
@ -60,8 +74,19 @@ class Dialyzer(Model):
def confirm(self,ids,context={}):
id=ids[0]
obj=self.browse(id)
prod=obj.product_id
ship_address_id=0 #TODO contract address
patient=obj.patient_id
if not patient:
raise Exception("Patient is required")
partner=patient.partner_id
if not partner:
raise Exception("Contact not for this patient")
ship_address_id=None
for address in partner.addresses:
if address.type=="shipping":
ship_address_id=address.id
break
if not ship_address_id:
raise Exception("contact %s dont'have address with type shipping"%partner.name)
pick_vals={
"type": "out",
"ref": obj.number,
@ -71,10 +96,13 @@ class Dialyzer(Model):
"lines": [],
"state": "draft",
}
res=get_model("stock.location").search([["type","=","customer"]])
if not res:
raise Exception("Customer location not found")
cust_loc_id=res[0]
prod=obj.product_id
wh_loc_id=prod.location_id.id
if not wh_loc_id:
res=get_model("stock.location").search([["type","=","internal"]])
@ -93,9 +121,68 @@ class Dialyzer(Model):
return {
"flash": "Nothing left to deliver",
}
pick_id=get_model("stock.picking").create(pick_vals,context={"pick_type": "out"})
pick=get_model("stock.picking").browse(pick_id)
picking_obj=get_model("stock.picking")
pick_id=picking_obj.create(pick_vals,context={"pick_type": "out"})
pick=picking_obj.browse(pick_id)
pick.set_done([pick_id])
obj.write({"state": "active"})
return {
'next':{
'name': 'clinic_dialyzer',
'mode': 'form',
'active_id': obj.id
},
'flash': 'Dializer %s is confirmed'%(obj.number),
}
print("Done!")
def delete(self,ids,context={}):
for obj in self.browse(ids):
if obj.state != 'new':
raise Exception("Can not delete Dializer %s because state is not 'new'"%obj.number)
def cancel(self,ids,context={}):
obj=self.browse(ids[0])
for pick in obj.pickings:
pick.to_draft(context)
pick.delete()
obj.write({
'state': 'cancelled',
})
return {
'next':{
'name': 'clinic_dialyzer',
'mode': 'form',
'active_id': obj.id
},
'flash': 'Dializer %s is cancelled'%(obj.number),
}
def renew(self,ids,context={}):
obj=self.browse(ids[0])
obj.write({"state": "new"})
def drop(self,ids,context={}):
obj=self.browse(ids[0])
obj.write({"state": "drop"})
def copy(self,ids,context={}):
obj=self.browse(ids[0])
vals={
'patient_id': obj.patient_id.id,
'pickings':[],
}
new_id=self.create(vals,context=context)
new_obj=self.browse(new_id)
return {
'next':{
'name': 'clinic_dialyzer',
'mode': 'form',
'active_id': new_id,
},
'flash': 'Dializer %s is copy to %s'%(obj.number,new_obj.number),
}
Dialyzer.register()

View File

@ -156,7 +156,7 @@ class Patient(Model):
get_model("partner").delete(partner_ids)
super().delete(ids)
def write(self,ids,vals,**kw):
def _write(self,ids,vals,**kw):
partner_id=vals.get('partner_id')
if not partner_id:
obj=self.browse(ids[0])