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