diff --git a/procurement_auto_create_group/README.rst b/procurement_auto_create_group/README.rst new file mode 100644 index 000000000..60802c2af --- /dev/null +++ b/procurement_auto_create_group/README.rst @@ -0,0 +1,71 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +============================= +Procurement Auto Create Group +============================= + +This module allows the system to propose automatically new procurement groups +in procurement orders. + +This capability is important when you want to make sure that all the stock +moves resulting from this procurement will never be mixed with moves from +other groups in stock transfers. + +The stock transfers resulting from the execution of these procurements will +only contain stock moves created from that procurement. + + +Configuration +============= + +#. Go to *Inventory / Configuration / Settings* and check the option 'Advanced + routing of products using rules' and press the 'Apply' button. +#. Activate the developer mode. +#. Go to *Inventory / Configuration / Routes / Routes* and check the option + 'Auto-create Procurement Group' to the pull rules where you want the + procurement groups to be automatically proposed. + +Usage +===== + +#. Go to *Inventory / Reports / Procurement Exceptions*. +#. Create a new procurement order and make sure that it determines a pull rule + with the option 'Auto-create Procurement Group' set. +#. When you save the procurement order, a procurement group with format + 'PG/000001' will be created. + +.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas + :alt: Try me on Runbot + :target: https://runbot.odoo-community.org/runbot/153/9.0 + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, please +check there if your issue has already been reported. If you spotted it first, +help us smashing it by providing a detailed and welcomed feedback. + +Credits +======= + +Contributors +------------ +* Jordi Ballester + +Maintainer +---------- + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +This module is maintained by the OCA. + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +To contribute to this module, please visit https://odoo-community.org. diff --git a/procurement_auto_create_group/__init__.py b/procurement_auto_create_group/__init__.py new file mode 100644 index 000000000..d21be936d --- /dev/null +++ b/procurement_auto_create_group/__init__.py @@ -0,0 +1,5 @@ +# # -*- coding: utf-8 -*- +# Copyright 2017 Eficent Business and IT Consulting Services, S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import models diff --git a/procurement_auto_create_group/__openerp__.py b/procurement_auto_create_group/__openerp__.py new file mode 100644 index 000000000..c8adee87c --- /dev/null +++ b/procurement_auto_create_group/__openerp__.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Eficent Business and IT Consulting Services, S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +{ + "name": "Procurement Auto Create Group", + "version": "9.0.1.0.0", + "depends": [ + "procurement", + ], + "author": "Eficent," + "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/stock-logistics-warehouse", + "category": "Warehouse Management", + "data": [ + 'views/procurement_view.xml', + ], + "installable": True, + "license": "AGPL-3", +} diff --git a/procurement_auto_create_group/models/__init__.py b/procurement_auto_create_group/models/__init__.py new file mode 100644 index 000000000..01a85acda --- /dev/null +++ b/procurement_auto_create_group/models/__init__.py @@ -0,0 +1,6 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Eficent Business and IT Consulting Services, S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from . import procurement_rule +from . import procurement diff --git a/procurement_auto_create_group/models/procurement.py b/procurement_auto_create_group/models/procurement.py new file mode 100644 index 000000000..dcc782b33 --- /dev/null +++ b/procurement_auto_create_group/models/procurement.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +# -*- coding: utf-8 -*- +# Copyright 2017 Eficent Business and IT Consulting Services, S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp import api, models, _ +from openerp.exceptions import UserError + + +class ProcurementOrder(models.Model): + _inherit = 'procurement.order' + + @api.model + def _prepare_auto_procurement_group_data(self, procurement): + name = self.env['ir.sequence'].next_by_code( + 'procurement.group') or False + if not name: + raise UserError(_('No sequence defined for procurement group')) + return { + 'name': name + } + + @api.model + def _assign(self, procurement): + res = super(ProcurementOrder, self)._assign(procurement) + + if (procurement.rule_id and not procurement.group_id and + procurement.rule_id.auto_create_group): + group_data = self._prepare_auto_procurement_group_data(procurement) + group = self.env['procurement.group'].create(group_data) + procurement.group_id = group + return res diff --git a/procurement_auto_create_group/models/procurement_rule.py b/procurement_auto_create_group/models/procurement_rule.py new file mode 100644 index 000000000..1f767b387 --- /dev/null +++ b/procurement_auto_create_group/models/procurement_rule.py @@ -0,0 +1,10 @@ +# -*- coding: utf-8 -*- +# Copyright 2017 Eficent Business and IT Consulting Services, S.L. +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +from openerp import fields, models + + +class ProcurementRule(models.Model): + _inherit = 'procurement.rule' + + auto_create_group = fields.Boolean(string='Auto-create Procurement Group') diff --git a/procurement_auto_create_group/static/description/icon.png b/procurement_auto_create_group/static/description/icon.png new file mode 100644 index 000000000..3a0328b51 Binary files /dev/null and b/procurement_auto_create_group/static/description/icon.png differ diff --git a/procurement_auto_create_group/views/procurement_view.xml b/procurement_auto_create_group/views/procurement_view.xml new file mode 100644 index 000000000..c8b6c1d17 --- /dev/null +++ b/procurement_auto_create_group/views/procurement_view.xml @@ -0,0 +1,16 @@ + + + + + procurement.rule.form + procurement.rule + + + + + + + + +