diff --git a/netforce_clinic/layouts/clinic_shop_form.xml b/netforce_clinic/layouts/clinic_shop_form.xml
index eeb86ce..6245a88 100644
--- a/netforce_clinic/layouts/clinic_shop_form.xml
+++ b/netforce_clinic/layouts/clinic_shop_form.xml
@@ -39,10 +39,27 @@
-
+
-
+
+
+
+
+
+ {{#each context.data}}
+
+ {{/each}}
+
+
+
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index c935e9b..a1a7d1f 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -116,6 +116,7 @@ from . import matching_hdcase
from . import sale_order
from . import shop
from . import shop_line
+from . import shop_payment
from . import product
from . import base_user
from . import select_company
diff --git a/netforce_clinic/models/shop.py b/netforce_clinic/models/shop.py
index f8b50d1..a25b16e 100644
--- a/netforce_clinic/models/shop.py
+++ b/netforce_clinic/models/shop.py
@@ -16,12 +16,20 @@ class Shop(Model):
st=get_model("clinic.setting").browse(1)
shop_categs=[x.id for x in st.shop_categs]
for obj in self.browse(ids):
- total=0
+ sub_total=0
+ tax_amount=0 #XXX
for line in obj.lines:
amt=line.amount or 0
- total+=amt
+ sub_total+=amt
+ total=sub_total
+ total=total-tax_amount
+ for pm in obj.payments:
+ total-=pm.amount_payment
res[obj.id]={
+ 'sub_total': sub_total,
+ 'tax_amount': tax_amount,
'total': total,
+ 'due_amount': total,
'shop_categs': shop_categs,
}
return res
@@ -36,7 +44,10 @@ class Shop(Model):
'department_id': fields.Many2One("clinic.department","Department",search=True),
'branch_id': fields.Many2One("clinic.branch","Branch",search=True),
'lines': fields.One2Many('clinic.shop.line','shop_id','Lines'),
+ 'sub_total': fields.Float("Subtotal",function="_get_all",function_multi=True),
'total': fields.Float("Total",function="_get_all",function_multi=True),
+ 'due_amount': fields.Float("Due Amount",function="_get_all",function_multi=True),
+ 'tax_amount': fields.Float("Tax Amount",function="_get_all",function_multi=True),
'user_id': fields.Many2One("base.user","Sale Man"),
'state': fields.Selection([['draft','Draft'],['waiting_payment','Waiting Payment'],['paid','Paid'],['cancelled','Cancelled']],'State'),
"pickings": fields.One2Many("stock.picking","related_id","Pickings"),
@@ -54,6 +65,7 @@ class Shop(Model):
'cheque_no': fields.Char("Cheque No."),
'hd_case_call': fields.Boolean("HD Case Call"),
'note': fields.Text("Note"),
+ "payment_lines": fields.One2Many("clinic.shop.payment","shop_id","Payment Lines"),
}
@@ -450,6 +462,10 @@ class Shop(Model):
obj.write({
'state': 'paid',
'pay_type': 'cash',
+ 'payment_lines': [('create',{
+ 'payment_id': payment_id,
+ 'amount': payment.amount_payment,
+ })],
})
def to_draft(self,ids,context={}):
@@ -468,6 +484,8 @@ class Shop(Model):
for picking in obj.pickings:
picking.to_draft(context=context)
picking.delete()
+ for pm_line in obj.payment_lines:
+ pm_line.delete()
obj.write({
'state': 'draft',
})
diff --git a/netforce_clinic/models/shop_payment.py b/netforce_clinic/models/shop_payment.py
new file mode 100644
index 0000000..d22a2e3
--- /dev/null
+++ b/netforce_clinic/models/shop_payment.py
@@ -0,0 +1,19 @@
+from netforce.model import Model, fields
+
+class ShopPayment(Model):
+ _name="clinic.shop.payment"
+ _transient=True
+
+ _fields={
+ 'shop_id': fields.Many2One("clinic.hd.case","HD Case",on_delete="cascade"),
+ 'payment_id': fields.Many2One("account.payment","Payment",on_delete="cascade"),
+ 'account_id': fields.Many2One("account.account","Account"),
+ 'amount': fields.Float("Amount"),
+ }
+
+ _defaults={
+ 'amount': 0.0,
+ }
+
+ShopPayment.register()
+