overide function post in account invoice
parent
f84eced255
commit
e05909fe05
|
@ -13,6 +13,7 @@
|
||||||
<field name="contact_id" required='1' span="2"/>
|
<field name="contact_id" required='1' span="2"/>
|
||||||
<field name="branch_id" span="2"/>
|
<field name="branch_id" span="2"/>
|
||||||
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
|
<field name="department_id" domain='[["branch_id","=",branch_id]]' span="2"/>
|
||||||
|
<field name="related_id" span="3"/>
|
||||||
<field name="shop_categs" invisible="1"/>
|
<field name="shop_categs" invisible="1"/>
|
||||||
<tabs>
|
<tabs>
|
||||||
<tab string="General">
|
<tab string="General">
|
||||||
|
@ -36,7 +37,6 @@
|
||||||
<tab string="Other">
|
<tab string="Other">
|
||||||
<group form_layout="stacked">
|
<group form_layout="stacked">
|
||||||
<field name="user_id" span="3"/>
|
<field name="user_id" span="3"/>
|
||||||
<field name="related_id" span="3"/>
|
|
||||||
</group>
|
</group>
|
||||||
</tab>
|
</tab>
|
||||||
</tabs>
|
</tabs>
|
||||||
|
|
|
@ -46,6 +46,7 @@ from . import gen_visit_time
|
||||||
from . import payment
|
from . import payment
|
||||||
from . import account_payment
|
from . import account_payment
|
||||||
from . import account_invoice
|
from . import account_invoice
|
||||||
|
from . import account_invoice_line
|
||||||
from . import staff
|
from . import staff
|
||||||
from . import staff_categ
|
from . import staff_categ
|
||||||
from . import staff_level
|
from . import staff_level
|
||||||
|
|
|
@ -93,8 +93,21 @@ class AccountInvoice(Model):
|
||||||
"partner_id": partner.id,
|
"partner_id": partner.id,
|
||||||
}
|
}
|
||||||
lines.append(line_vals)
|
lines.append(line_vals)
|
||||||
if hdcase:
|
#XXX
|
||||||
pass
|
ar_debit=line.ar_debit_id
|
||||||
|
if hdcase and ar_debit:
|
||||||
|
amt=amt*-1
|
||||||
|
line_vals={
|
||||||
|
"description": line.description,
|
||||||
|
"account_id": ar_debit.id,
|
||||||
|
"credit": amt>0 and amt or 0,
|
||||||
|
"debit": amt<0 and -amt or 0,
|
||||||
|
"track_id": line.track_id.id,
|
||||||
|
"track2_id": line.track2_id.id,
|
||||||
|
"partner_id": partner.id,
|
||||||
|
}
|
||||||
|
lines.append(line_vals)
|
||||||
|
|
||||||
for comp_id,tax_vals in taxes.items():
|
for comp_id,tax_vals in taxes.items():
|
||||||
comp=get_model("account.tax.component").browse(comp_id)
|
comp=get_model("account.tax.component").browse(comp_id)
|
||||||
acc_id=comp.account_id.id
|
acc_id=comp.account_id.id
|
||||||
|
@ -169,16 +182,20 @@ class AccountInvoice(Model):
|
||||||
amt=0
|
amt=0
|
||||||
for line in group_lines:
|
for line in group_lines:
|
||||||
amt-=line["debit"]-line["credit"]
|
amt-=line["debit"]-line["credit"]
|
||||||
line_vals={
|
#XXX
|
||||||
"description": desc,
|
if amt >0:
|
||||||
"account_id": account_id,
|
line_vals={
|
||||||
"debit": amt>0 and amt or 0,
|
"description": desc,
|
||||||
"credit": amt<0 and -amt or 0,
|
"account_id": account_id,
|
||||||
"due_date": obj.due_date,
|
"debit": amt>0 and amt or 0,
|
||||||
"partner_id": partner.id,
|
"credit": amt<0 and -amt or 0,
|
||||||
}
|
"due_date": obj.due_date,
|
||||||
move_vals["lines"]=[("create",line_vals)]
|
"partner_id": partner.id,
|
||||||
move_vals["lines"]+=[("create",vals) for vals in group_lines]
|
}
|
||||||
|
move_vals["lines"]=[("create",line_vals)]
|
||||||
|
move_vals["lines"]+=[("create",vals) for vals in group_lines]
|
||||||
|
else:
|
||||||
|
move_vals["lines"]=[("create",vals) for vals in group_lines]
|
||||||
t03=time.time()
|
t03=time.time()
|
||||||
dt02=(t03-t02)*1000
|
dt02=(t03-t02)*1000
|
||||||
print("post dt02",dt02)
|
print("post dt02",dt02)
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
import time
|
||||||
|
|
||||||
|
from netforce.model import Model, fields, get_model
|
||||||
|
|
||||||
|
class AccountInvoiceLine(Model):
|
||||||
|
_inherit="account.invoice.line"
|
||||||
|
_fields={
|
||||||
|
'ar_credit_id': fields.Many2One("account.account","Account Credit"),
|
||||||
|
"ar_debit_id": fields.Many2One("account.account","Account Debit"),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
AccountInvoiceLine.register()
|
|
@ -385,6 +385,8 @@ class HDCase(Model):
|
||||||
rmb_lines=[] #yes
|
rmb_lines=[] #yes
|
||||||
normb_lines=[] #no
|
normb_lines=[] #no
|
||||||
cst=get_model('clinic.setting').browse(1)
|
cst=get_model('clinic.setting').browse(1)
|
||||||
|
prod_acc=cst.get_product_account
|
||||||
|
|
||||||
for line in obj.lines:
|
for line in obj.lines:
|
||||||
if line.state!='draft':
|
if line.state!='draft':
|
||||||
continue
|
continue
|
||||||
|
@ -393,19 +395,23 @@ class HDCase(Model):
|
||||||
prod=line.product_id
|
prod=line.product_id
|
||||||
print("#1.find in line")
|
print("#1.find in line")
|
||||||
account_id=line.account_id.id
|
account_id=line.account_id.id
|
||||||
if not account_id:
|
ar_debit_id=line.ar_debit_id.id
|
||||||
|
if not account_id or not ar_debit_id:
|
||||||
print("#2.find in ratchawat setting")
|
print("#2.find in ratchawat setting")
|
||||||
prod_acc=cst.get_product_account
|
|
||||||
acc=prod_acc(prod.id,obj.patient_type_id.id)
|
acc=prod_acc(prod.id,obj.patient_type_id.id)
|
||||||
account_id=acc.get("ar_credit_id",None)
|
account_id=acc.get("ar_credit_id",None)
|
||||||
print("#3.find account in account setting -> income account")
|
ar_debit_id=acc.get("ar_debit_id",None)
|
||||||
if not account_id and not prod:
|
#print("#3.find account in account setting -> income account")
|
||||||
account_id=setting.income_account_id.id
|
#if not account_id and not prod:
|
||||||
print("#4.find in product(tab accounting)")
|
#account_id=setting.income_account_id.id
|
||||||
|
#print("#4.find in product(tab accounting)")
|
||||||
|
#if not account_id:
|
||||||
|
#account_id=prod.sale_account_id.id
|
||||||
if not account_id:
|
if not account_id:
|
||||||
account_id=prod.sale_account_id.id
|
raise Exception("No Income Credit Account for product [%s] %s"%(prod.code, prod.name))
|
||||||
if not account_id:
|
if not ar_debit_id:
|
||||||
raise Exception("Please define account for product [%s] %s"%(prod.code, prod.name))
|
raise Exception("No Ar Debit Account for product [%s] %s"%(prod.code, prod.name))
|
||||||
|
|
||||||
if line.reimbursable=='yes':
|
if line.reimbursable=='yes':
|
||||||
rmb_lines.append(('create',{
|
rmb_lines.append(('create',{
|
||||||
"product_id": prod.id,
|
"product_id": prod.id,
|
||||||
|
@ -415,6 +421,7 @@ class HDCase(Model):
|
||||||
"unit_price": line.price or 0,
|
"unit_price": line.price or 0,
|
||||||
"amount": line.amount or 0,
|
"amount": line.amount or 0,
|
||||||
'account_id': account_id,
|
'account_id': account_id,
|
||||||
|
'ar_debit_id': ar_debit_id,
|
||||||
}))
|
}))
|
||||||
else:
|
else:
|
||||||
normb_lines.append(('create',{
|
normb_lines.append(('create',{
|
||||||
|
@ -425,6 +432,7 @@ class HDCase(Model):
|
||||||
"unit_price": line.price or 0,
|
"unit_price": line.price or 0,
|
||||||
"amount": line.amount or 0,
|
"amount": line.amount or 0,
|
||||||
'account_id': account_id,
|
'account_id': account_id,
|
||||||
|
'ar_debit_id': ar_debit_id,
|
||||||
}))
|
}))
|
||||||
|
|
||||||
patient=obj.patient_id
|
patient=obj.patient_id
|
||||||
|
@ -988,6 +996,7 @@ class HDCase(Model):
|
||||||
amt=st_prod.amount
|
amt=st_prod.amount
|
||||||
categ=st_prod.product_categ_id
|
categ=st_prod.product_categ_id
|
||||||
account_id=prod_acc.get("ar_credit_id",None)
|
account_id=prod_acc.get("ar_credit_id",None)
|
||||||
|
ar_debit_id=prod_acc.get("ar_debit_id",None)
|
||||||
if not amt:
|
if not amt:
|
||||||
amt=qty*price
|
amt=qty*price
|
||||||
line_vals={
|
line_vals={
|
||||||
|
@ -999,15 +1008,16 @@ class HDCase(Model):
|
||||||
'reimbursable': st_prod.reimbursable,
|
'reimbursable': st_prod.reimbursable,
|
||||||
'amount': amt,
|
'amount': amt,
|
||||||
'account_id': account_id,
|
'account_id': account_id,
|
||||||
|
'ar_debit_id': ar_debit_id,
|
||||||
}
|
}
|
||||||
if prod:
|
if prod:
|
||||||
line_vals.update({
|
line_vals.update({
|
||||||
'product_id': prod.id,
|
'product_id': prod.id,
|
||||||
})
|
})
|
||||||
if not line_vals['account_id']:
|
#if not line_vals['account_id']:
|
||||||
line_vals['account_id']=prod.sale_account_id.id
|
#line_vals['account_id']=prod.sale_account_id.id
|
||||||
if not line_vals['account_id']:
|
#if not line_vals['account_id']:
|
||||||
raise Exception("Please contact accountant: product [%s] %s"%(prod.code, prod.name))
|
#raise Exception("Please contact accountant: product [%s] %s"%(prod.code, prod.name))
|
||||||
vals['lines'].append(('create',line_vals))
|
vals['lines'].append(('create',line_vals))
|
||||||
# XXX need to get default
|
# XXX need to get default
|
||||||
partner=patient.type_id.contact_id
|
partner=patient.type_id.contact_id
|
||||||
|
|
|
@ -15,7 +15,8 @@ class Hdcaseline(Model):
|
||||||
"product_categ_id": fields.Many2One("product.categ","Category",domain=[['expense','=',True]]),
|
"product_categ_id": fields.Many2One("product.categ","Category",domain=[['expense','=',True]]),
|
||||||
'reimbursable': fields.Selection([['yes','Yes'],['no','No']],"Reimbursable"),
|
'reimbursable': fields.Selection([['yes','Yes'],['no','No']],"Reimbursable"),
|
||||||
'state': fields.Selection([['draft','Draft'],['done','Done']],"State"),
|
'state': fields.Selection([['draft','Draft'],['done','Done']],"State"),
|
||||||
"account_id": fields.Many2One("account.account","Account"),
|
"account_id": fields.Many2One("account.account","Account Credit"),
|
||||||
|
"ar_debit_id": fields.Many2One("account.account","Account Debit"),
|
||||||
}
|
}
|
||||||
|
|
||||||
def _get_categ(self,context={}):
|
def _get_categ(self,context={}):
|
||||||
|
|
Loading…
Reference in New Issue