clinic/netforce_clinic/models/account_invoice.py

53 lines
1.8 KiB
Python
Raw Normal View History

2015-02-03 08:37:43 +00:00
from netforce.model import Model, fields, get_model
2014-10-27 14:17:22 +00:00
2014-12-14 11:15:14 +00:00
class AccountInvoice(Model):
_inherit="account.invoice"
_fields={
'clinic_expense_id': fields.Many2One("clinic.hd.case.expense","Expense"),
2015-01-20 13:58:38 +00:00
'department_id': fields.Many2One("clinic.department","Department",search=True),
2015-03-04 07:19:53 +00:00
'patient_partner_id': fields.Many2One("partner","Patient",search=True),
2015-03-18 14:40:58 +00:00
'hdcase_credit': fields.Boolean("HD Case Credit"),
2014-12-14 11:15:14 +00:00
}
2015-03-18 01:39:03 +00:00
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,
}
2015-02-03 08:37:43 +00:00
2015-03-04 07:19:53 +00:00
2014-12-14 11:15:14 +00:00
AccountInvoice.register()