clinic/netforce_clinic/models/hd_case_popup_discontinue.py

79 lines
2.4 KiB
Python
Raw Normal View History

2014-10-05 09:43:28 +00:00
from netforce.model import Model, fields, get_model
2015-01-15 05:15:46 +00:00
class HDCasePopupDiscontinue(Model):
_name="clinic.hd.case.popup.discontinue"
2014-10-05 09:43:28 +00:00
_transient=True
_fields={
"hd_case_id": fields.Many2One("clinic.hd.case","HdCase",required=True,on_delete="cascade"),
"note": fields.Text("Description"),
2015-01-11 11:23:28 +00:00
"lines": fields.One2Many("clinic.hd.case.line","hd_case_dis_id","Lines"),
2014-10-05 09:43:28 +00:00
}
def _get_hd_case_id(self,context={}):
hd_case_id=context.get("refer_id")
2014-11-14 01:58:12 +00:00
print("hd case deault")
2014-10-05 09:43:28 +00:00
if not hd_case_id:
return None
return int(hd_case_id)
2015-01-11 11:23:28 +00:00
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
2014-10-05 09:43:28 +00:00
_defaults={
'hd_case_id': _get_hd_case_id,
2015-01-11 11:23:28 +00:00
'lines': _get_lines,
2014-10-05 09:43:28 +00:00
}
def do_discontinue(self,ids,context):
obj=self.browse(ids)[0]
hd_case=get_model("clinic.hd.case").browse(obj.hd_case_id.id)
hd_case.write({
'note': obj.note,
2014-11-29 14:56:15 +00:00
'state': 'cancelled',
2014-10-05 09:43:28 +00:00
})
2015-03-17 04:35:48 +00:00
hd_case.sickbed_id.write({
'available': True,
})
2015-01-11 11:23:28 +00:00
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)
2014-10-05 09:43:28 +00:00
return {
'next': {
'name': 'clinic_hd_case',
'mode': 'form',
'active_id': hd_case.id,
},
'flash': '%s has been cancelled'%hd_case.number,
}
2015-01-15 05:15:46 +00:00
HDCasePopupDiscontinue.register()
2014-10-05 09:43:28 +00:00