diff --git a/netforce_clinic/layouts/clinic_account_setting.xml b/netforce_clinic/layouts/clinic_account_setting.xml
index 670cc93..41c0877 100644
--- a/netforce_clinic/layouts/clinic_account_setting.xml
+++ b/netforce_clinic/layouts/clinic_account_setting.xml
@@ -28,6 +28,7 @@
+
diff --git a/netforce_clinic/layouts/clinic_hd_case_form.xml b/netforce_clinic/layouts/clinic_hd_case_form.xml
index 55cb4cc..e2f3447 100644
--- a/netforce_clinic/layouts/clinic_hd_case_form.xml
+++ b/netforce_clinic/layouts/clinic_hd_case_form.xml
@@ -60,7 +60,8 @@
-
+
+
diff --git a/netforce_clinic/layouts/clinic_prod_form.xml b/netforce_clinic/layouts/clinic_prod_form.xml
new file mode 100644
index 0000000..ed2a5e8
--- /dev/null
+++ b/netforce_clinic/layouts/clinic_prod_form.xml
@@ -0,0 +1,5 @@
+
+
+
+
+
diff --git a/netforce_clinic/layouts/clinic_prod_list.xml b/netforce_clinic/layouts/clinic_prod_list.xml
index b2432ab..789d7ef 100644
--- a/netforce_clinic/layouts/clinic_prod_list.xml
+++ b/netforce_clinic/layouts/clinic_prod_list.xml
@@ -1,4 +1,4 @@
-
+
diff --git a/netforce_clinic/layouts/clinic_setting.xml b/netforce_clinic/layouts/clinic_setting.xml
index 271b0a7..4f8054b 100644
--- a/netforce_clinic/layouts/clinic_setting.xml
+++ b/netforce_clinic/layouts/clinic_setting.xml
@@ -12,13 +12,9 @@
-
-
+
-
-
-
@@ -28,6 +24,9 @@
+
+
+
diff --git a/netforce_clinic/layouts/clinic_shop_form.xml b/netforce_clinic/layouts/clinic_shop_form.xml
index ac16c50..a61ea71 100644
--- a/netforce_clinic/layouts/clinic_shop_form.xml
+++ b/netforce_clinic/layouts/clinic_shop_form.xml
@@ -42,7 +42,8 @@
-
+
+
diff --git a/netforce_clinic/models/__init__.py b/netforce_clinic/models/__init__.py
index cfd4eb9..e989af6 100644
--- a/netforce_clinic/models/__init__.py
+++ b/netforce_clinic/models/__init__.py
@@ -1,10 +1,11 @@
from . import utils
from . import setting
-from . import fin_setting
-from . import setting_account_product
from . import setting_product
+from . import setting_account_product
+from . import setting_shop_product
from . import setting_level
from . import setting_policy
+from . import fin_setting
from . import cause_chronic
from . import comorbidity
from . import department
@@ -98,3 +99,4 @@ from . import matching_payment
from . import shop
from . import shop_line
from . import sale_order
+from . import product
diff --git a/netforce_clinic/models/hd_case.py b/netforce_clinic/models/hd_case.py
index 0df9595..c184e72 100644
--- a/netforce_clinic/models/hd_case.py
+++ b/netforce_clinic/models/hd_case.py
@@ -398,15 +398,12 @@ class HDCase(Model):
ar_debit_id=line.ar_debit_id.id
if not account_id or not ar_debit_id:
print("#2.find in ratchawat setting")
- acc=prod_acc(prod.id,obj.patient_type_id.id)
+ if line.reimbursable=='yes':
+ acc=prod_acc(prod.id,obj.patient_type_id.id)
+ else:
+ acc=prod_acc(prod.id,obj.patient_type_id.id,'cash')
account_id=acc.get("ar_credit_id",None)
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:
raise Exception("No Income Credit Account for product [%s] %s"%(prod.code, prod.name))
if not ar_debit_id:
diff --git a/netforce_clinic/models/product.py b/netforce_clinic/models/product.py
new file mode 100644
index 0000000..b8a29a5
--- /dev/null
+++ b/netforce_clinic/models/product.py
@@ -0,0 +1,9 @@
+from netforce.model import Model, fields
+
+class Product(Model):
+ _inherit="product"
+ _fields={
+ 'patient_types': fields.Many2Many("clinic.patient.type","Patient Types"),
+ }
+
+Product.register()
diff --git a/netforce_clinic/models/setting.py b/netforce_clinic/models/setting.py
index 22f07d7..5f4a786 100644
--- a/netforce_clinic/models/setting.py
+++ b/netforce_clinic/models/setting.py
@@ -13,6 +13,7 @@ class ClinicSetting(Model):
'levels': fields.One2Many("clinic.setting.level","setting_id","Levels"),
'products': fields.One2Many("clinic.setting.product","setting_id","Products"),
'account_products': fields.One2Many("clinic.setting.account.product","setting_id","Account Products"),
+ 'shop_products': fields.One2Many("clinic.setting.shop.product","setting_id","Shop Products"),
'invoice_policies': fields.One2Many("clinic.setting.policy","setting_id","Invoice Policies"),
'cost_per_case': fields.Float("Cost Per Case"),
'company_id': fields.Many2One("company", 'Company'),
@@ -29,6 +30,7 @@ class ClinicSetting(Model):
'department_id': fields.Many2One("clinic.department","Department"),
'branch_id': fields.Many2One("clinic.branch","Branch"),
'shop_categs': fields.Many2Many("product.categ","Categs"),
+ 'shop_type_id': fields.Many2One("clinic.patient.type","Patient Type"),
}
_defaults={
@@ -73,9 +75,6 @@ class ClinicSetting(Model):
data=context['data']
path=context['path']
line=get_data_path(data,path,parent=True)
- ptype_id=line['patient_type_id']
- ptype=get_model("clinic.patient.type").browse(ptype_id)
- line['type_code']=ptype.code or ''
return data
def onchange_setting_line(self,context={}):
@@ -106,6 +105,35 @@ class ClinicSetting(Model):
if user_id !=1:
print("Only admin!!")
return
+ obj=self.browse(1)
+ t={}
+ [t.update({x.code : x.id}) for x in get_model("clinic.patient.type").search_browse([])]
+ for prod in get_model("product").search_browse([]):
+ code=prod.code or ""
+ tcodes=code.split("-")
+ tids=[]
+ for tcode in tcodes:
+ tid=t.get(tcode,None)
+ if tid:
+ tids.append(tid)
+
+ prod.write({
+ 'patient_types': [('add',tids)]
+ })
+ print("Done!")
+ return
+
+ for line in obj.account_products:
+ acc=line.ar_debit_id
+ type='credit'
+ if acc:
+ if acc.code=='101101':
+ type='cash'
+ line.write({
+ 'type': type,
+ })
+ print("Done!")
+ return
for vs in get_model("clinic.visit").search_browse([['state','in', ['draft','pending']],['doctor_id','=',None]]):
doctor=vs.patient_id.doctor_id
if doctor:
@@ -136,13 +164,13 @@ class ClinicSetting(Model):
print("to draft payment ", payment.id)
print("Done")
- def get_product_account(self,ids,prod_id=None,patient_type_id=None,context={}):
+ def get_product_account(self,ids,prod_id=None,patient_type_id=None,pay_type='credit',context={}):
res={}
- print("find ", prod_id, patient_type_id)
- for ac_prod in get_model("clinic.setting.account.product").search_browse([]):
+ print("find ", prod_id, patient_type_id, pay_type)
+ dom=[['type','=',pay_type]]
+ for ac_prod in get_model("clinic.setting.account.product").search_browse(dom):
prod=ac_prod.product_id
ptype=ac_prod.patient_type_id
- print(prod.id, ':: ', ptype.id)
if patient_type_id==ptype.id and prod_id==prod.id:
print("found !")
res.update({
diff --git a/netforce_clinic/models/setting_account_product.py b/netforce_clinic/models/setting_account_product.py
index b669546..69e854c 100644
--- a/netforce_clinic/models/setting_account_product.py
+++ b/netforce_clinic/models/setting_account_product.py
@@ -14,6 +14,7 @@ class SettingAccountProduct(Model):
"ar_credit_id": fields.Many2One("account.account","Income Credit",multi_company=True),
"ar_debit_id": fields.Many2One("account.account","AR Debit",multi_company=True),
'company_id': fields.Many2One("company","Company"),
+ "type": fields.Selection([("cash","Cash"),("credit","Credit")],"Type"),
}
_defaults={
diff --git a/netforce_clinic/models/setting_shop_product.py b/netforce_clinic/models/setting_shop_product.py
new file mode 100644
index 0000000..935b36a
--- /dev/null
+++ b/netforce_clinic/models/setting_shop_product.py
@@ -0,0 +1,24 @@
+from netforce.model import Model, fields
+from netforce.access import get_active_company
+
+class SettingShopProduct(Model):
+ _name="clinic.setting.shop.product"
+ _string="Setting Shop Product"
+ _multi_company=True
+
+ _fields={
+ "setting_id": fields.Many2One("clinic.setting","Setting",required=True,on_delete="cascade"),
+ 'categ_id': fields.Many2One("product.categ","Category"),
+ "product_id": fields.Many2One("product","Product"),
+ "ar_credit_id": fields.Many2One("account.account","Sale Account",multi_company=True),
+ "ar_debit_id": fields.Many2One("account.account","AR Debit",multi_company=True),
+ 'company_id': fields.Many2One("company","Company"),
+ }
+
+ _defaults={
+ "company_id": lambda *a: get_active_company(),
+ }
+
+ _order="categ_id"
+
+SettingShopProduct.register()
diff --git a/netforce_clinic/models/shop.py b/netforce_clinic/models/shop.py
index da845ed..bb50aed 100644
--- a/netforce_clinic/models/shop.py
+++ b/netforce_clinic/models/shop.py
@@ -1,7 +1,7 @@
import time
from netforce.model import Model, fields, get_model
-from netforce.access import get_active_user
+from netforce.access import get_active_user, set_active_user
from netforce.utils import get_data_path
class Shop(Model):
@@ -72,6 +72,20 @@ class Shop(Model):
patient_id=hd_case.patient_id.id
return patient_id
+ def _get_number(self,context={}):
+ while 1:
+ seq_id=get_model("sequence").find_sequence(name="Clinic RD Shop")
+ num=get_model("sequence").get_next_number(seq_id,context=context)
+ if not num:
+ return None
+ user_id=get_active_user()
+ set_active_user(1)
+ res=self.search([["number","=",num]])
+ set_active_user(user_id)
+ if not res:
+ return num
+ get_model("sequence").increment_number(seq_id,context=context)
+
_defaults={
'number': '/',
'date': lambda *a: time.strftime("%Y-%m-%d"),
@@ -142,13 +156,43 @@ class Shop(Model):
super().write(ids,vals,**kw)
self.function_store(ids)
- def pay(self,ids,context={}):
+ def pay_credit(self,ids,context={}):
obj=self.browse(ids)[0]
active_id=obj.id
action="clinic_shop"
if obj.related_id:
active_id=obj.related_id.id
action="clinic_hd_case"
+ st=get_model("clinic.setting").browse(1)
+ if not st.shop_type_id:
+ raise Exception("Please defind Shop Type on menu Clinic Settings -> RD Shop")
+ if obj.number=="/":
+ obj.write({
+ 'number': self._get_number(),
+ })
+ return {
+ 'next': {
+ 'name': action,
+ 'mode': 'form',
+ 'active_id': active_id,
+ },
+ 'flash': 'Pay Successfully',
+ }
+
+ def pay_cash(self,ids,context={}):
+ obj=self.browse(ids)[0]
+ active_id=obj.id
+ action="clinic_shop"
+ if obj.related_id:
+ active_id=obj.related_id.id
+ action="clinic_hd_case"
+ st=get_model("clinic.setting").browse(1)
+ if not st.shop_type_id:
+ raise Exception("Please defind Shop Type on menu Clinic Settings -> RD Shop")
+ if obj.number=="/":
+ obj.write({
+ 'number': self._get_number()
+ })
return {
'next': {
'name': action,
diff --git a/netforce_clinic/models/shop_line.py b/netforce_clinic/models/shop_line.py
index 89d8108..400571c 100644
--- a/netforce_clinic/models/shop_line.py
+++ b/netforce_clinic/models/shop_line.py
@@ -14,6 +14,7 @@ class ShopLine(Model):
'price': fields.Float("Price"),
'amount': fields.Float("Amount"),
'account_id': fields.Many2One("account.account","Account"),
+ 'ar_debit_id': fields.Many2One("account.account","Account Debit"),
}
ShopLine.register()
diff --git a/netforce_clinic/todo.txt b/netforce_clinic/todo.txt
index 1042399..4b3c2d8 100644
--- a/netforce_clinic/todo.txt
+++ b/netforce_clinic/todo.txt
@@ -1,4 +1,8 @@
todo:
+ - sale medicine ***
+ - payment
+ - matching payment ***
+ - script generate hd case
- accounting
- labor cost
- report ->ok
@@ -7,13 +11,10 @@ todo:
- doctor
- total hd case
- invoice line -> account -> credit
- - debit from hd case setting
- - if user select product by them self
+ - if user select product by them self -> testing
- credit <= product -> tab -> accounting -> sale -> sale account
- debit <= 1. contact -> tab accounting -> account receiaveble , 2. finacial setting -> account receiable
- - sale medicine
- - payment ***
- - matching payment ***
+
- patient