discontinue

conv_bal
watcha.h@almacom.co.th 2015-01-11 18:23:28 +07:00
parent 81cedff701
commit 238f2f35b4
5 changed files with 62 additions and 6 deletions

View File

@ -1,6 +1,14 @@
<form model="clinic.hd.case.discont">
<field name="hd_case_id" invisible="1"/>
<field name="note" nolabel="1" width="550" height="200"/>
<field name="note" nolabel="1" width="450" height="200"/>
<separator string="Good issue: remove line below if no need to create."/>
<field name="lines" nolabel="1" no_add="1" count="0">
<list>
<field name="product_id"/>
<field name="uom_id"/>
<field name="qty"/>
</list>
</field>
<foot>
<button string="OK" type="success" method="do_discontinue"/>
</foot>

View File

@ -8,7 +8,7 @@
</head>
<group form_layout="stacked" attrs='{"readonly":[["state","=","completed"]]}'>
<field name="number" span="2"/>
<field name="sickbed_id" attrs='{"readonly":[["state","in",["completed","waiting_payment","paid"]]]}' domain="[['state','=','available']]" required="1" span="2"/>
<field name="sickbed_id" attrs='{"readonly":[["state","in",["completed","waiting_payment","paid","cancelled"]]]}' domain="[['state','=','available']]" required="1" span="2"/>
<field name="patient_id" span="2" onchange="onchange_patient"/>
<field name="patient_type_id" span="2"/>
<field name="cycle_id" span="2" required="1" onchange="onchange_cycle"/>

View File

@ -508,17 +508,26 @@ class HDCase(Model):
if not res:
raise Exception("Customer location not found")
cust_loc_id=res[0]
#XXX
no_lines=context.get('no_line') or False
if no_lines:
return
prod_ids=context.get('prod_ids') or []
prod_exist_ids=[]
for line in obj.lines:
if line.state!='draft':
continue
prod=line.product_id
if prod.type != 'stock':
print("continue ")
continue
#XXX
if prod_ids and prod.id not in prod_ids or prod.id in prod_exist_ids:
continue
prod_exist_ids.append(prod.id)
if not wh_loc_id:
wh_loc_id=prod.location_id.id
if not wh_loc_id:
@ -975,6 +984,8 @@ class HDCase(Model):
if mode=='create':
line_vals=line[1]
amt=line_vals.get("amount",0)
if mode=='delete':
continue
else:
line_id=line[1][0]
line_vals=line[2]

View File

@ -7,6 +7,7 @@ class HDCaseDiscont(Model):
_fields={
"hd_case_id": fields.Many2One("clinic.hd.case","HdCase",required=True,on_delete="cascade"),
"note": fields.Text("Description"),
"lines": fields.One2Many("clinic.hd.case.line","hd_case_dis_id","Lines"),
}
def _get_hd_case_id(self,context={}):
@ -16,8 +17,33 @@ class HDCaseDiscont(Model):
return None
return int(hd_case_id)
def _get_lines(self,context={}):
hd_case_id=context.get("refer_id")
lines=[]
if not hd_case_id:
return lines
hd_case=get_model("clinic.hd.case").browse(hd_case_id)
for line in hd_case.lines:
prod=line.product_id
if prod.type != 'stock':
print("continue ")
continue
lines.append({
'hd_case_id': hd_case_id,
'product_id': prod.id,
'uom_id': line.uom_id.id,
'product_categ_id': line.product_categ_id.id,
'description': line.description,
'price': line.price,
'qty': line.qty,
'reimbursable': line.reimbursable,
'amount': line.amount,
})
return lines
_defaults={
'hd_case_id': _get_hd_case_id,
'lines': _get_lines,
}
def do_discontinue(self,ids,context):
@ -27,6 +53,16 @@ class HDCaseDiscont(Model):
'note': obj.note,
'state': 'cancelled',
})
prod_ids=[]
for line in obj.lines:
prod=line.product_id
prod_ids.append(prod.id)
line.delete()
context['prod_ids']=prod_ids
if not prod_ids:
context['no_line']=True
hd_case.make_pickings(context=context)
return {
'next': {
'name': 'clinic_hd_case',

View File

@ -3,7 +3,8 @@ from netforce.model import Model, fields
class Hdcaseline(Model):
_name="clinic.hd.case.line"
_fields={
"hd_case_id": fields.Many2One("clinic.hd.case","HdCase",required=True,on_delete="cascade"),
"hd_case_id": fields.Many2One("clinic.hd.case","HD Case",required=True,on_delete="cascade"),
"hd_case_dis_id": fields.Many2One("clinic.hd.case.discont","HD Case",on_delete="cascade"),
"product_id": fields.Many2One("product","Product",search=True),
"description": fields.Char("Description",search=True),
"qty":fields.Integer("QTY"),