2015-01-21 01:35:55 +00:00
|
|
|
import time
|
|
|
|
|
|
|
|
from netforce.model import Model, fields, get_model
|
|
|
|
from netforce.access import get_active_user
|
|
|
|
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={}
|
|
|
|
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-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-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-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-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-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-01-23 10:28:08 +00:00
|
|
|
Shop.register()
|