import time from netforce.model import Model, fields, get_model from netforce.access import get_active_company class CycleItem(Model): _name="clinic.cycle.item" _string="Cycle Item" _name_field="name" def _get_all(self,ids,context): res={} for obj in self.browse(ids): name="%s-%s"%(obj.cycle_id.name,obj.date) res[obj.id]={ 'name': name, } return res _fields={ 'name': fields.Char("Name", function="_get_all",function_multi=True), # need to field related in journal 'company_id': fields.Many2One("company", "Company"), 'cycle_id': fields.Many2One("clinic.cycle", "Cycle",search=True), 'date': fields.Date("Date",search=True), "state": fields.Selection([("draft","Draft"),("done","Done")],"Status",required=True), 'hd_cases': fields.One2Many("clinic.hd.case","cycle_item_id", "HD Cases"), 'visits': fields.One2Many("clinic.visit","cycle_item_id", "Visits"), 'nurses': fields.One2Many("clinic.cycle.item.nurse",'cycle_item_id','Nurses'), 'doctors': fields.One2Many("clinic.cycle.item.doctor",'cycle_item_id','Doctors'), 'sequence': fields.Char("Sequence"), } _defaults={ 'state': 'draft', 'company_id': lambda *a: get_active_company(), 'date': lambda *a: time.strftime("%Y-%m-%d"), } _order="sequence" def create(self, vals,**kw): date=vals['date'] cycle_id=vals['cycle_id'] cycle=get_model("clinic.cycle").browse(cycle_id) vals['sequence']='%s-%s'%(date,cycle.sequence) #date-sequence obj_id=super().create(vals,**kw) return obj_id def write(self,ids,vals,**kw): obj=self.browse(ids)[0] cycle=obj.cycle_id vals['sequence']='%s-%s'%(obj.date,cycle.sequence) #date-sequence super().write(ids,vals,**kw) CycleItem.register()