from netforce.model import Model, fields, get_model class HDCasePopupDiscontinue(Model): _name="clinic.hd.case.popup.discontinue" _transient=True _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={}): hd_case_id=context.get("refer_id") print("hd case deault") if not hd_case_id: 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): obj=self.browse(ids)[0] hd_case=get_model("clinic.hd.case").browse(obj.hd_case_id.id) hd_case.write({ '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', 'mode': 'form', 'active_id': hd_case.id, }, 'flash': '%s has been cancelled'%hd_case.number, } HDCasePopupDiscontinue.register()