From 01eaa8533588347d0b04e2df34af4465867ad9df Mon Sep 17 00:00:00 2001 From: "watcha.h" Date: Fri, 19 Aug 2016 16:34:23 +0700 Subject: [PATCH] some dummy function to create master product from there child --- netforce_clinic/models/product.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/netforce_clinic/models/product.py b/netforce_clinic/models/product.py index 235721d..36b3fd3 100644 --- a/netforce_clinic/models/product.py +++ b/netforce_clinic/models/product.py @@ -2,6 +2,7 @@ from netforce.model import Model, fields class Product(Model): _inherit="product" + _fields={ 'patient_types': fields.Many2Many("clinic.patient.type","Patient Types"), 'departments': fields.One2Many('clinic.department.product','product_id','Departments'), @@ -9,4 +10,31 @@ class Product(Model): 'account_products': fields.One2Many('clinic.setting.account.product','product_id','Account Products'), } + #TODO + def copy_master(self,ids,context={}): + obj=self.browse(ids)[0] + master_code=obj.code.split("-")[0] + dom=[ + ['code','=',master_code] + ] + res=self.search(dom) + if res: + raise Exception("Master product is already exist") + vals={ + 'code': master_code, + 'name': obj.name.split("-")[0], + 'description': obj.description, + 'categ_id': obj.categ_id and obj.categ_id.id, + } + new_id=self.create(vals) + return { + 'next': { + 'name': 'product', + 'mode': 'form', + 'active_id': new_id, + }, + 'flash': "Copy master product successfull", + } + + Product.register()