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-08-04 12:05:45 +00:00
|
|
|
# override this function to push tracking
|
|
|
|
def create_fixed_assets(self,ids,context={}):
|
|
|
|
for obj in self.browse(ids):
|
|
|
|
if obj.fixed_assets:
|
|
|
|
raise Exception("Fixed assets already created for invoice %s"%obj.number)
|
|
|
|
for line in obj.lines:
|
|
|
|
acc=line.account_id
|
|
|
|
if acc.type!="fixed_asset":
|
|
|
|
continue
|
|
|
|
ass_type=acc.fixed_asset_type_id
|
|
|
|
if not ass_type:
|
|
|
|
continue
|
|
|
|
vals={
|
|
|
|
"name": line.description,
|
|
|
|
"type_id": ass_type.id,
|
|
|
|
"date_purchase": obj.date,
|
|
|
|
"price_purchase": line.amount, # XXX: should be tax-ex
|
|
|
|
"fixed_asset_account_id": acc.id,
|
|
|
|
"dep_rate": ass_type.dep_rate,
|
|
|
|
"dep_method": ass_type.dep_method,
|
|
|
|
"accum_dep_account_id": ass_type.accum_dep_account_id.id,
|
|
|
|
"dep_exp_account_id": ass_type.dep_exp_account_id.id,
|
|
|
|
"invoice_id": obj.id,
|
|
|
|
'track_id': line.track_id.id,
|
|
|
|
}
|
|
|
|
get_model("account.fixed.asset").create(vals)
|
2015-03-04 07:19:53 +00:00
|
|
|
|
2014-12-14 11:15:14 +00:00
|
|
|
AccountInvoice.register()
|