mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[ADD] mod stock_orderpoint_creator
(lp:c2c-addons/6.1 rev 28.1.12)
This commit is contained in:
24
stock_orderpoint_creator/__init__.py
Normal file
24
stock_orderpoint_creator/__init__.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Author: Yannick Vaucher (Camptocamp)
|
||||
# Copyright 2012 Camptocamp SA
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from . import base_product_config_template
|
||||
from . import orderpoint_template
|
||||
from . import wizard
|
||||
43
stock_orderpoint_creator/__openerp__.py
Normal file
43
stock_orderpoint_creator/__openerp__.py
Normal file
@@ -0,0 +1,43 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Author: Yannick Vaucher (Camptocamp)
|
||||
# Copyright 2012 Camptocamp SA
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
{'name': 'Configuration of order point in mass',
|
||||
'version': '1.0',
|
||||
'author': 'Camptocamp',
|
||||
'maintainer': 'Camptocamp',
|
||||
'category': 'Warehouse',
|
||||
'complexity': 'easy', #easy, normal, expert
|
||||
'depends': ['procurement'],
|
||||
'description': """
|
||||
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"],
|
||||
'demo_xml': [],
|
||||
'test': [],
|
||||
'installable': True,
|
||||
'images': [],
|
||||
'auto_install': False,
|
||||
'license': 'AGPL-3',
|
||||
'active': False,
|
||||
}
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
78
stock_orderpoint_creator/base_product_config_template.py
Normal file
78
stock_orderpoint_creator/base_product_config_template.py
Normal file
@@ -0,0 +1,78 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Author: Yannick Vaucher (Camptocamp)
|
||||
# Copyright 2012 Camptocamp SA
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
""" Base template for product config """
|
||||
|
||||
|
||||
class BaseProductConfigTemplate():
|
||||
""" Abstract template for product config """
|
||||
#_name = 'stock.warehouse.orderpoint.template'
|
||||
|
||||
#_inherit = 'stock.warehouse.orderpoint'
|
||||
#_table = 'stock_warehouse_orderpoint_template'
|
||||
|
||||
|
||||
def _get_model(self):
|
||||
""" Get the model for which this template is defined
|
||||
|
||||
return a browse record of the model for which
|
||||
is represented by this template
|
||||
"""
|
||||
model = self._inherit
|
||||
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
|
||||
return must return a list of id"""
|
||||
return []
|
||||
|
||||
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)
|
||||
|
||||
|
||||
def create_instances(
|
||||
self, cursor, uid, template_id, product_ids, context=None):
|
||||
""" Create instances of model using template """
|
||||
|
||||
if not isinstance(product_ids, list):
|
||||
product_ids = [product_ids]
|
||||
|
||||
self._disable_old_instances(
|
||||
cursor, uid, template_id, product_ids, context=context)
|
||||
|
||||
data = self.copy_data(cursor, uid, template_id, context=context)
|
||||
|
||||
model_obj = self._get_model()
|
||||
|
||||
for product_id in product_ids:
|
||||
data['product_id'] = product_id
|
||||
model_obj.create(cursor, uid, data, context=context)
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
55
stock_orderpoint_creator/orderpoint_template.py
Normal file
55
stock_orderpoint_creator/orderpoint_template.py
Normal file
@@ -0,0 +1,55 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Author: Yannick Vaucher (Camptocamp)
|
||||
# Copyright 2012 Camptocamp SA
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
""" Template of order point object """
|
||||
|
||||
from osv import osv, fields
|
||||
from base_product_config_template import BaseProductConfigTemplate
|
||||
|
||||
class OrderpointTemplate(BaseProductConfigTemplate, osv.osv_memory):
|
||||
""" Template for orderpoints """
|
||||
_name = 'stock.warehouse.orderpoint.template'
|
||||
|
||||
_inherit = 'stock.warehouse.orderpoint'
|
||||
_table = 'stock_warehouse_orderpoint_template'
|
||||
|
||||
_columns = {
|
||||
'product_id': fields.many2one('product.product',
|
||||
'Product',
|
||||
required=False,
|
||||
ondelete='cascade',
|
||||
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"""
|
||||
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),
|
||||
('product_id', 'in', product_ids)]
|
||||
|
||||
ids2clean = model_obj.search(cursor, uid, search_args, context=context)
|
||||
return ids2clean
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
22
stock_orderpoint_creator/wizard/__init__.py
Normal file
22
stock_orderpoint_creator/wizard/__init__.py
Normal file
@@ -0,0 +1,22 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Author: Yannick Vaucher (Camptocamp)
|
||||
# Copyright 2012 Camptocamp SA
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from . import orderpoint_creator
|
||||
71
stock_orderpoint_creator/wizard/orderpoint_creator.py
Normal file
71
stock_orderpoint_creator/wizard/orderpoint_creator.py
Normal file
@@ -0,0 +1,71 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# Author: Yannick Vaucher (Camptocamp)
|
||||
# Copyright 2012 Camptocamp SA
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU Affero General Public License as
|
||||
# published by the Free Software Foundation, either version 3 of the
|
||||
# License, or (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU Affero General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Affero General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
""" Wizard defining stock.warehouse.orderpoint configurations for selected
|
||||
products. Those configs are generated using templates """
|
||||
|
||||
from osv import osv, fields
|
||||
|
||||
_template_register = ['orderpoint_template_id']
|
||||
|
||||
class OrderpointCreator(osv.osv_memory):
|
||||
_name = 'stock.warehouse.orderpoint.creator'
|
||||
_description = 'Orderpoint Creator'
|
||||
|
||||
_columns = {
|
||||
'orderpoint_template_id': fields.many2one(
|
||||
'stock.warehouse.orderpoint.template',
|
||||
"Stock rule template")
|
||||
}
|
||||
|
||||
|
||||
def _get_template_register(self):
|
||||
"""return a list of the field names which defines a template
|
||||
This is a hook to allow expending the list of template"""
|
||||
return _template_register
|
||||
|
||||
|
||||
def action_configure(self, cursor, uid, ids, context=None):
|
||||
""" action to retrieve wizard data and launch creation of items """
|
||||
|
||||
product_ids = context['active_ids']
|
||||
|
||||
wiz_fields_template = self._get_template_register()
|
||||
template_ids = self.read(
|
||||
cursor, uid, ids, wiz_fields_template, context=context)[0]
|
||||
|
||||
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
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
31
stock_orderpoint_creator/wizard/orderpoint_creator_view.xml
Normal file
31
stock_orderpoint_creator/wizard/orderpoint_creator_view.xml
Normal file
@@ -0,0 +1,31 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<record id="orderpoint_creator_view" model="ir.ui.view">
|
||||
<field name="name">stock.warehouse.orderpoint.creator</field>
|
||||
<field name="model">stock.warehouse.orderpoint.creator</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<group string="templates">
|
||||
<field name="orderpoint_template_id"/>
|
||||
</group>
|
||||
<group colspan="2" col="4">
|
||||
<button special="cancel" string="Cancel" icon="gtk-cancel"/>
|
||||
<button name="action_configure" string="Apply" type="object" icon="gtk-execute"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<act_window name="Product warehouse config"
|
||||
res_model="stock.warehouse.orderpoint.creator"
|
||||
src_model="product.product"
|
||||
view_mode="form"
|
||||
target="new"
|
||||
key2="client_action_multi"
|
||||
id="act_create_product_conf"/>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user