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 Shop(Model): _name="clinic.shop" _string="Shop" 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), 'department_id': fields.Many2One("clinic.department","Department"), 'branch_id': fields.Many2One("clinic.branch","Branch"), 'lines': fields.One2Many('clinic.shop.line','shop_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"), } 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] _defaults={ 'number': '/', 'date': lambda *a: time.strftime("%Y-%m-%d"), 'user_id': lambda *a: get_active_user(), 'branch_id': _get_branch, 'department_id': _get_department, '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 Shop.register()