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
|
|
|
|
|
|
|
|
class Pharmacy(Model):
|
|
|
|
_name="clinic.pharmacy"
|
|
|
|
_string="Pharmacy"
|
|
|
|
|
|
|
|
def _get_all(self,ids,context={}):
|
|
|
|
res={}
|
|
|
|
for obj in self.browse(ids):
|
|
|
|
res[obj.id]={
|
|
|
|
'total': 0,
|
|
|
|
}
|
|
|
|
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-21 01:35:55 +00:00
|
|
|
'lines': fields.One2Many('clinic.pharmacy.line','pharmacy_id','Lines'),
|
|
|
|
'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-22 10:40:05 +00:00
|
|
|
"orders": fields.One2Many("sale.order","pharmacy_id","Orders"),
|
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',
|
|
|
|
}
|
|
|
|
|
|
|
|
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']
|
|
|
|
return data
|
|
|
|
|
|
|
|
Pharmacy.register()
|