mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] review of stock_orderpoint_creator
(lp:c2c-addons/6.1 rev 28.1.14)
This commit is contained in:
@@ -21,4 +21,4 @@
|
||||
|
||||
from . import base_product_config_template
|
||||
from . import orderpoint_template
|
||||
from . import wizard
|
||||
import wizard
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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()
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user