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), '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"), "payments": fields.One2Many("account.payment","related_id","Payments"), } _defaults={ 'date': lambda *a: time.strftime("%Y-%m-%d"), 'number': '/', 'user_id': lambda *a: get_active_user(), '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()