from netforce.model import Model, fields, get_model class AccountInvoice(Model): _inherit="account.invoice" _fields={ 'clinic_expense_id': fields.Many2One("clinic.hd.case.expense","Expense"), 'department_id': fields.Many2One("clinic.department","Department",search=True), 'patient_partner_id': fields.Many2One("partner","Patient",search=True), } def _get_number(self,context={}): defaults=context.get("defaults") if defaults: # XXX type=defaults.get("type") inv_type=defaults.get("inv_type") else: type=context.get("type") inv_type=context.get("inv_type") seq_type=None if type=="out": if inv_type in ("invoice","prepay"): seq_type="cust_invoice" elif inv_type=="credit": seq_type="cust_credit" elif inv_type=="debit": seq_type="cust_debit" elif type=="in": if inv_type in ("invoice","prepay"): seq_type="supp_invoice" elif inv_type=="credit": seq_type="supp_credit" elif inv_type=="debit": seq_type="supp_debit" if not seq_type: return seq_id=get_model("sequence").find_sequence(type=seq_type,context=context) if not seq_id: return None while 1: num=get_model("sequence").get_next_number(seq_id,context=context) res=self.search([["number","=",num]]) if not res: return num get_model("sequence").increment_number(seq_id,context=context) _defaults={ "number": _get_number, } AccountInvoice.register()