import time from netforce.model import Model, fields from netforce.access import get_active_company class HDCaseExpense(Model): _name="clinic.hd.case.expense" _string="Expense" _name_field="date" _multi_company=True def _get_patient_conflict(self,ids,context={}): res={} for obj in self.browse(ids): hd_case=obj.hd_case_id patient=hd_case.patient_id conflict=False if obj.patient_id.id!=patient.id: conflict=True res[obj.id]=conflict return res _fields={ 'date': fields.Date("Date",required=True,search=True), 'patient_id': fields.Many2One("clinic.patient","Patient",required=True,search=True), 'hd_case_id': fields.Many2One("clinic.hd.case","HD Case",required=True,search=True), 'invoice_id': fields.Many2One("account.invoice","Invoice",search=True), 'payment_id': fields.Many2One("account.payment","Payment",search=True), 'amount': fields.Float("Amount"), 'state': fields.Selection([['draft','Draft'],['waiting_matching','Waiting Matching'],['match','Match'],['unmatch','Unmatch'],['approved','Approved']],'State'), 'note': fields.Text("Note"), 'pt_conflict': fields.Boolean("Patient Conclict",function="_get_patient_conflict"), 'company_id': fields.Many2One("company","Company"), } _defaults={ 'state': 'draft', 'date': time.strftime("%Y-%m-%d"), "company_id": lambda *a: get_active_company(), } _order="date desc" def approve(self,ids,context={}): obj=self.browse(ids)[0] obj.write({ 'state': 'approved', }) def to_draft(self,ids,context={}): obj=self.browse(ids)[0] obj.write({ 'state': 'draft', }) def delete(self,ids,context={}): for obj in self.browse(ids): if obj.state!='draft': raise Exception("Status is not draft!") super().delete(ids,context) def do_match(self,ids,context={}): obj=self.browse(ids)[0] obj.write({ 'state': 'match', }) def do_unmatch(self,ids,context={}): obj=self.browse(ids)[0] obj.write({ 'state': 'unmatch', }) def cancel(self,ids,context={}): obj=self.browse(ids)[0] obj.write({ 'state': 'cancelled', }) HDCaseExpense.register()