80 lines
2.9 KiB
Python
80 lines
2.9 KiB
Python
import time
|
|
|
|
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,
|
|
}
|
|
|
|
# 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)
|
|
|
|
AccountInvoice.register()
|