diff --git a/netforce_clinic/layouts/clinic_shop_form.xml b/netforce_clinic/layouts/clinic_shop_form.xml
index d034a84..ac16c50 100644
--- a/netforce_clinic/layouts/clinic_shop_form.xml
+++ b/netforce_clinic/layouts/clinic_shop_form.xml
@@ -13,6 +13,7 @@
+
@@ -36,7 +37,6 @@
-
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index 5cdb378..cfd4eb9 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -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
diff --git a/netforce_clinic/models/account_invoice.py b/netforce_clinic/models/account_invoice.py
index e5a087b..a37783e 100644
--- a/netforce_clinic/models/account_invoice.py
+++ b/netforce_clinic/models/account_invoice.py
@@ -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,16 +182,20 @@ class AccountInvoice(Model):
amt=0
for line in group_lines:
amt-=line["debit"]-line["credit"]
- line_vals={
- "description": desc,
- "account_id": account_id,
- "debit": amt>0 and amt or 0,
- "credit": amt<0 and -amt or 0,
- "due_date": obj.due_date,
- "partner_id": partner.id,
- }
- move_vals["lines"]=[("create",line_vals)]
- move_vals["lines"]+=[("create",vals) for vals in group_lines]
+ #XXX
+ if amt >0:
+ line_vals={
+ "description": desc,
+ "account_id": account_id,
+ "debit": amt>0 and amt or 0,
+ "credit": amt<0 and -amt or 0,
+ "due_date": obj.due_date,
+ "partner_id": partner.id,
+ }
+ 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)
diff --git a/netforce_clinic/models/account_invoice_line.py b/netforce_clinic/models/account_invoice_line.py
new file mode 100644
index 0000000..0d20259
--- /dev/null
+++ b/netforce_clinic/models/account_invoice_line.py
@@ -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()
diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py
index d8ad886..0df9595 100644
--- a/netforce_clinic/models/hd_case.py
+++ b/netforce_clinic/models/hd_case.py
@@ -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
diff --git a/netforce_clinic/models/hd_case_line.py b/netforce_clinic/models/hd_case_line.py
index bbc5a9e..6456b31 100644
--- a/netforce_clinic/models/hd_case_line.py
+++ b/netforce_clinic/models/hd_case_line.py
@@ -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={}):