From d04c0ae97d10c7639a6d0a015db829ba067587be Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 24 May 2012 10:50:35 +0200 Subject: [PATCH] [IMP] review of stock_orderpoint_creator (lp:c2c-addons/6.1 rev 28.1.14) --- stock_orderpoint_creator/__init__.py | 2 +- stock_orderpoint_creator/__openerp__.py | 2 +- .../base_product_config_template.py | 36 +++++++++---------- .../orderpoint_template.py | 15 ++++---- .../wizard/orderpoint_creator.py | 30 +++++++--------- 5 files changed, 36 insertions(+), 49 deletions(-) diff --git a/stock_orderpoint_creator/__init__.py b/stock_orderpoint_creator/__init__.py index b8cf874c8..34ffb14a7 100644 --- a/stock_orderpoint_creator/__init__.py +++ b/stock_orderpoint_creator/__init__.py @@ -21,4 +21,4 @@ from . import base_product_config_template from . import orderpoint_template -from . import wizard +import wizard diff --git a/stock_orderpoint_creator/__openerp__.py b/stock_orderpoint_creator/__openerp__.py index f1c855f10..356a13164 100644 --- a/stock_orderpoint_creator/__openerp__.py +++ b/stock_orderpoint_creator/__openerp__.py @@ -30,7 +30,7 @@ Add a wizard to configure massively order points for multiple product""", 'website': 'http://www.openerp.com', 'init_xml': [], - 'update_xml': ["wizard/orderpoint_creator_view.xml"], + 'update_xml': ["wizard/orderpoint_creator_view.xml", "security/ir.model.access.csv"], 'demo_xml': [], 'test': [], 'installable': True, diff --git a/stock_orderpoint_creator/base_product_config_template.py b/stock_orderpoint_creator/base_product_config_template.py index 2c9843143..4cf6b7d77 100644 --- a/stock_orderpoint_creator/base_product_config_template.py +++ b/stock_orderpoint_creator/base_product_config_template.py @@ -23,11 +23,7 @@ class BaseProductConfigTemplate(): - """ Abstract template for product config """ - #_name = 'stock.warehouse.orderpoint.template' - - #_inherit = 'stock.warehouse.orderpoint' - #_table = 'stock_warehouse_orderpoint_template' + """ Abstract class for product config """ def _get_model(self): @@ -40,33 +36,33 @@ class BaseProductConfigTemplate(): model_obj = self.pool.get(model) return model_obj - def _get_ids_2_clean( - self, cursor, uid, template_id, product_ids, context=None): - """ hook to select model specific objects to clean + def _get_ids_2_clean(self, cursor, uid, template_br, + product_ids, context=None): + """ hook to select model specific objects to clean return must return a list of id""" return [] - def _disable_old_instances( - self, cursor, uid, template_id, product_ids, context=None): + def _disable_old_instances(self, cursor, uid, template_id, + product_ids, context=None): """ Clean old instance by setting those inactives """ model_obj = self._get_model() - ids2clean = self._get_ids_2_clean( - cursor, uid, template_id, product_ids, context=context) - model_obj.write( - cursor, uid, ids2clean, {'active': False}, context=context) + ids2clean = self._get_ids_2_clean(cursor, uid, template_id, + product_ids, context=context) + model_obj.write(cursor, uid, ids2clean, + {'active': False}, context=context) - def create_instances( - self, cursor, uid, template_id, product_ids, context=None): - """ Create instances of model using template """ + def create_instances(self, cursor, uid, template_br, + product_ids, context=None): + """ Create instances of model using template inherited model """ if not isinstance(product_ids, list): product_ids = [product_ids] - self._disable_old_instances( - cursor, uid, template_id, product_ids, context=context) + self._disable_old_instances(cursor, uid, template_br, + product_ids, context=context) - data = self.copy_data(cursor, uid, template_id, context=context) + data = self.copy_data(cursor, uid, template_br.id, context=context) model_obj = self._get_model() diff --git a/stock_orderpoint_creator/orderpoint_template.py b/stock_orderpoint_creator/orderpoint_template.py index 78550cd68..cd49d66a3 100644 --- a/stock_orderpoint_creator/orderpoint_template.py +++ b/stock_orderpoint_creator/orderpoint_template.py @@ -21,10 +21,10 @@ """ Template of order point object """ -from osv import osv, fields +from openerp.osv.orm import TransientModel, fields from base_product_config_template import BaseProductConfigTemplate -class OrderpointTemplate(BaseProductConfigTemplate, osv.osv_memory): +class OrderpointTemplate(BaseProductConfigTemplate, TransientModel): """ Template for orderpoints """ _name = 'stock.warehouse.orderpoint.template' @@ -39,14 +39,11 @@ class OrderpointTemplate(BaseProductConfigTemplate, osv.osv_memory): domain=[('type','=','product')]), } - def _get_ids_2_clean( - self, cursor, uid, template_id, product_ids, context=None): - """ hook to select model specific objects to clean - return must return a list of id""" + def _get_ids_2_clean(self, cursor, uid, template_br, product_ids, context=None): + """ hook to select model specific objects to clean before recteating new one + return must return a list of id. """ model_obj = self._get_model() - (warehouse_id, warehouse_name) = self.read( - cursor, uid, template_id, ['warehouse_id'])['warehouse_id'] - search_args = [('warehouse_id', '=', warehouse_id), + search_args = [('warehouse_id', '=', template_br.warehouse_id.id), ('product_id', 'in', product_ids)] ids2clean = model_obj.search(cursor, uid, search_args, context=context) diff --git a/stock_orderpoint_creator/wizard/orderpoint_creator.py b/stock_orderpoint_creator/wizard/orderpoint_creator.py index 7e8f1547d..1601876ec 100644 --- a/stock_orderpoint_creator/wizard/orderpoint_creator.py +++ b/stock_orderpoint_creator/wizard/orderpoint_creator.py @@ -43,29 +43,23 @@ class OrderpointCreator(osv.osv_memory): return _template_register - def action_configure(self, cursor, uid, ids, context=None): + def action_configure(self, cursor, uid, wiz_id, context=None): """ action to retrieve wizard data and launch creation of items """ product_ids = context['active_ids'] + if isinstance(wiz_id, list): + wiz_id = wiz_id[0] + current = self.browse(cursor, uid, wiz_id, context=context) - wiz_fields_template = self._get_template_register() - template_ids = self.read( - cursor, uid, ids, wiz_fields_template, context=context)[0] + for template_field in self._get_template_register(): + template_br = current[template_field] + if template_br: + template_model = template_br._model._name + template_obj = self.pool.get(template_model) + template_obj.create_instances(cursor, uid, template_br, + product_ids, context=context) - for template_field in wiz_fields_template: - if template_ids[template_field]: - template_id = template_ids[template_field][0] - - # check if for this model a template has been defined - if template_id: - wiz_field = self.fields_get( - cursor, uid, allfields=template_field)[template_field] - template_model = wiz_field['relation'] - template_obj = self.pool.get(template_model) - template_obj.create_instances( - cursor, uid, template_id, product_ids, context=context) - - return True + return {} # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: