2015-01-21 01:35:55 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
from netforce.model import Model, fields, get_model
|
2015-02-04 05:13:10 +00:00
|
|
|
from netforce.access import get_active_user, set_active_user
|
2015-01-21 01:35:55 +00:00
|
|
|
from netforce.utils import get_data_path
|
|
|
|
|
2015-01-23 10:28:08 +00:00
|
|
|
class Shop(Model):
|
|
|
|
_name="clinic.shop"
|
|
|
|
_string="Shop"
|
2015-01-21 01:35:55 +00:00
|
|
|
|
|
|
|
def _get_all(self,ids,context={}):
|
|
|
|
res={}
|
2015-01-29 15:56:50 +00:00
|
|
|
st=get_model("clinic.setting").browse(1)
|
|
|
|
shop_categs=[x.id for x in st.shop_categs]
|
2015-01-21 01:35:55 +00:00
|
|
|
for obj in self.browse(ids):
|
2015-01-26 11:22:18 +00:00
|
|
|
total=0
|
|
|
|
for line in obj.lines:
|
|
|
|
amt=line.amount or 0
|
|
|
|
total+=amt
|
2015-01-21 01:35:55 +00:00
|
|
|
res[obj.id]={
|
2015-01-26 11:22:18 +00:00
|
|
|
'total': total,
|
2015-01-29 15:56:50 +00:00
|
|
|
'shop_categs': shop_categs,
|
2015-01-21 01:35:55 +00:00
|
|
|
}
|
|
|
|
return res
|
|
|
|
|
|
|
|
_fields={
|
|
|
|
"number": fields.Char("Number",required=True,search=True),
|
|
|
|
"ref": fields.Char("Ref",search=True),
|
|
|
|
'date': fields.Date("Date",search=True),
|
|
|
|
'patient_id': fields.Many2One('clinic.patient','Patient',search=True),
|
2015-02-02 10:47:19 +00:00
|
|
|
'contact_id': fields.Many2One('partner','Contact',search=True),
|
2015-01-22 10:40:05 +00:00
|
|
|
'department_id': fields.Many2One("clinic.department","Department"),
|
|
|
|
'branch_id': fields.Many2One("clinic.branch","Branch"),
|
2015-01-23 10:28:08 +00:00
|
|
|
'lines': fields.One2Many('clinic.shop.line','shop_id','Lines'),
|
2015-01-21 01:35:55 +00:00
|
|
|
'total': fields.Float("Total",function="_get_all",function_multi=True),
|
|
|
|
'user_id': fields.Many2One("base.user","Pharmacist"),
|
|
|
|
'state': fields.Selection([['draft','Draft'],['waiting_payment','Waiting Payment'],['paid','Paid']],'State'),
|
|
|
|
"pickings": fields.One2Many("stock.picking","related_id","Pickings"),
|
|
|
|
"invoices": fields.One2Many("account.invoice","related_id","Invoices"),
|
2015-01-23 10:28:08 +00:00
|
|
|
"payments": fields.One2Many("account.payment","related_id","Payments"),
|
2015-01-29 15:56:50 +00:00
|
|
|
'dom_str': fields.Char("Dom Str"),
|
2015-01-29 16:38:22 +00:00
|
|
|
'shop_categs': fields.Many2Many("product.categ","Categs",function="_get_all",function_multi=True,store=True),
|
|
|
|
"related_id": fields.Reference([["sale.order","Sales Order"],["purchase.order","Purchase Order"],["project","Project"],["job","Service Order"],["service.contract","Service Contract"]],"Related To"),
|
2015-01-21 01:35:55 +00:00
|
|
|
}
|
|
|
|
|
2015-01-22 10:40:05 +00:00
|
|
|
def _get_branch(self,context={}):
|
|
|
|
b_ids=get_model('clinic.branch').search([])
|
|
|
|
if b_ids:
|
|
|
|
return b_ids[0]
|
|
|
|
|
|
|
|
def _get_department(self,context={}):
|
|
|
|
dpt_ids=get_model('clinic.department').search([])
|
|
|
|
if dpt_ids:
|
|
|
|
return dpt_ids[0]
|
2015-01-29 16:38:22 +00:00
|
|
|
|
|
|
|
def _get_shop_categs(self,context={}):
|
|
|
|
st=get_model("clinic.setting").browse(1)
|
|
|
|
shop_categs=[x.id for x in st.shop_categs]
|
|
|
|
return shop_categs
|
|
|
|
|
|
|
|
def _get_related(self,context={}):
|
|
|
|
related_id=None
|
|
|
|
if context.get('refer_id'):
|
|
|
|
related_id="clinic.hd.case,%s"%context.get("refer_id")
|
|
|
|
return related_id
|
|
|
|
|
|
|
|
def _get_patient(self,context={}):
|
|
|
|
patient_id=None
|
|
|
|
if context.get('refer_id'):
|
|
|
|
refer_id=context.get("refer_id")
|
|
|
|
hd_case=get_model("clinic.hd.case").browse(refer_id)
|
|
|
|
patient_id=hd_case.patient_id.id
|
|
|
|
return patient_id
|
2015-01-22 10:40:05 +00:00
|
|
|
|
2015-02-04 05:13:10 +00:00
|
|
|
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)
|
|
|
|
|
2015-01-21 01:35:55 +00:00
|
|
|
_defaults={
|
|
|
|
'number': '/',
|
2015-01-22 10:40:05 +00:00
|
|
|
'date': lambda *a: time.strftime("%Y-%m-%d"),
|
2015-01-21 01:35:55 +00:00
|
|
|
'user_id': lambda *a: get_active_user(),
|
2015-01-22 10:40:05 +00:00
|
|
|
'branch_id': _get_branch,
|
|
|
|
'department_id': _get_department,
|
2015-01-21 01:35:55 +00:00
|
|
|
'state': 'draft',
|
2015-01-29 16:38:22 +00:00
|
|
|
'shop_categs': _get_shop_categs,
|
|
|
|
'related_id': _get_related,
|
|
|
|
'patient_id': _get_patient,
|
2015-01-21 01:35:55 +00:00
|
|
|
}
|
2015-01-26 11:22:18 +00:00
|
|
|
|
|
|
|
def update_all(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
data['total']=0
|
|
|
|
for line in data['lines']:
|
|
|
|
data['total']+=line['amount'] or 0
|
|
|
|
return data
|
|
|
|
|
|
|
|
def onchange_line(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
path=context['path']
|
|
|
|
line=get_data_path(data,path,parent=True)
|
|
|
|
line['amount']=(line['qty'] or 0)*(line['price'] or 0)
|
|
|
|
data=self.update_all(context=context)
|
|
|
|
return data
|
2015-01-21 01:35:55 +00:00
|
|
|
|
|
|
|
def onchange_product(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
path=context['path']
|
|
|
|
line=get_data_path(data,path,parent=True)
|
|
|
|
prod_id=line['product_id']
|
|
|
|
prod=get_model('product').browse(prod_id)
|
|
|
|
line['uom_id']=prod.uom_id.id
|
|
|
|
line['description']=prod.name or ''
|
|
|
|
line['price']=prod.sale_price or 0
|
|
|
|
if not line.get('qty'):
|
|
|
|
line['qty']=1
|
|
|
|
line['amount']=line['price']*line['qty']
|
2015-01-26 11:22:18 +00:00
|
|
|
data=self.update_all(context)
|
2015-01-21 01:35:55 +00:00
|
|
|
return data
|
2015-02-02 01:41:43 +00:00
|
|
|
|
|
|
|
def onchange_categ(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
path=context['path']
|
|
|
|
line=get_data_path(data,path,parent=True)
|
|
|
|
line['product_id']=None
|
|
|
|
return data
|
2015-02-02 10:47:19 +00:00
|
|
|
|
|
|
|
def onchange_patient(self,context={}):
|
|
|
|
data=context['data']
|
|
|
|
patient_id=data['patient_id']
|
|
|
|
patient=get_model("clinic.patient").browse(patient_id)
|
|
|
|
dpt=patient.department_id
|
|
|
|
branch=patient.branch_id
|
|
|
|
contact=patient.partner_id
|
|
|
|
data['department_id']=dpt.id
|
|
|
|
data['branch_id']=branch.id
|
|
|
|
data['contact_id']=contact.id
|
|
|
|
return data
|
2015-01-21 01:35:55 +00:00
|
|
|
|
2015-01-29 16:38:22 +00:00
|
|
|
def create(self,vals,**kw):
|
|
|
|
id=super().create(vals,**kw)
|
|
|
|
self.function_store([id])
|
|
|
|
return id
|
|
|
|
|
|
|
|
def write(self,ids,vals,**kw):
|
|
|
|
super().write(ids,vals,**kw)
|
|
|
|
self.function_store(ids)
|
|
|
|
|
2015-02-04 05:13:10 +00:00
|
|
|
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={}):
|
2015-01-29 16:38:22 +00:00
|
|
|
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"
|
2015-02-04 05:13:10 +00:00
|
|
|
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()
|
|
|
|
})
|
2015-01-29 16:38:22 +00:00
|
|
|
return {
|
|
|
|
'next': {
|
|
|
|
'name': action,
|
|
|
|
'mode': 'form',
|
|
|
|
'active_id': active_id,
|
|
|
|
},
|
|
|
|
'flash': 'Pay Successfully',
|
|
|
|
}
|
2015-01-29 15:56:50 +00:00
|
|
|
|
2015-01-23 10:28:08 +00:00
|
|
|
Shop.register()
|