[11.0][MIG] procurement_auto_create_group

This commit is contained in:
Lois Rilo
2018-09-18 13:19:26 +02:00
committed by HviorForgeFlow
parent 43756438c2
commit 9f00afafac
12 changed files with 169 additions and 97 deletions

View File

@@ -1,13 +1,29 @@
.. 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 file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
:target: https://odoo-community.org/page/development-status
:alt: Production/Stable
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--warehouse-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-warehouse/tree/11.0/procurement_auto_create_group
:alt: OCA/stock-logistics-warehouse
.. |badge4| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/153/11.0
:alt: Try me on Runbot
|badge1| |badge2| |badge3| |badge4|
This module allows the system to propose automatically new procurement groups
in procurement orders.
when procuring.
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
@@ -16,57 +32,67 @@ other groups in stock transfers.
The stock transfers resulting from the execution of these procurements will
only contain stock moves created from that procurement.
**Table of contents**
.. contents::
:local:
Configuration
=============
#. Go to *Inventory / Configuration / Settings* and check the option 'Advanced
routing of products using rules' and press the 'Apply' button.
#. Go to *Inventory / Configuration / Settings* and check the option
'Multi-Step Routes' and press the 'Save' 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.
#. Go to *Inventory / Configuration / Warehouse Management / Routes*
and select the route you want to change. Select the pull rule you wish
to change and Select 'Propagation of Procurement Group': 'Propagage'.
The checkbox 'Auto-create Procurement Group' will then appear and you can
set it if you want to procurement group to be automatically created.
Usage
=====
#. Go to *Inventory / Reports / Procurement Exceptions*.
#. Create a new procurement order and make sure that it determines a pull rule
#. Create a new procurement 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/10.0
#. When the procurement rule is executed, a procurement group with
format 'PG/000001' will be created.
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/stock-logistics-warehouse/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.
Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-warehouse/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.
Do not contact contributors directly about support or help with technical issues.
Credits
=======
Authors
~~~~~~~
* Eficent
Contributors
------------
~~~~~~~~~~~~
* Jordi Ballester <jordi.ballester@eficent.com>
* Lois Rilo <lois.rilo@eficent.com>
Maintainer
----------
Maintainers
~~~~~~~~~~~
This module is maintained by the OCA.
.. 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.
This module is part of the `OCA/stock-logistics-warehouse <https://github.com/OCA/stock-logistics-warehouse/tree/11.0/procurement_auto_create_group>`_ project on GitHub.
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

View File

@@ -1,4 +1 @@
# # -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import models

View File

@@ -1,19 +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": "10.0.1.0.0",
"version": "11.0.1.0.0",
"development_status": "Production/Stable",
"license": "AGPL-3",
"summary": "Allows to configure the system to propose automatically new "
"procurement groups in procurement orders.",
"depends": [
"procurement",
],
"author": "Eficent,"
"Odoo Community Association (OCA)",
"website": "https://github.com/OCA/stock-logistics-warehouse",
"category": "Warehouse Management",
"depends": [
"stock",
],
"data": [
'views/procurement_view.xml',
],

View File

@@ -1,6 +1,2 @@
# -*- 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
from . import procurement_group

View File

@@ -6,8 +6,17 @@ from odoo import api, models, _
from odoo.exceptions import UserError
class ProcurementOrder(models.Model):
_inherit = 'procurement.order'
class ProcurementGroup(models.Model):
_inherit = 'procurement.group'
@api.model
def _get_rule(self, product_id, location_id, values):
result = super()._get_rule(product_id, location_id, values)
if result and not values.get('group_id') and result.auto_create_group:
group_data = self._prepare_auto_procurement_group_data()
group = self.env['procurement.group'].create(group_data)
values['group_id'] = group
return result
@api.model
def _prepare_auto_procurement_group_data(self):
@@ -18,13 +27,3 @@ class ProcurementOrder(models.Model):
return {
'name': name
}
@api.multi
def _assign(self):
res = super(ProcurementOrder, self)._assign()
if (self.rule_id and not self.group_id and
self.rule_id.auto_create_group):
group_data = self._prepare_auto_procurement_group_data()
group = self.env['procurement.group'].create(group_data)
self.group_id = group
return res

View File

@@ -0,0 +1,8 @@
#. Go to *Inventory / Configuration / Settings* and check the option
'Multi-Step Routes' and press the 'Save' button.
#. Activate the developer mode.
#. Go to *Inventory / Configuration / Warehouse Management / Routes*
and select the route you want to change. Select the pull rule you wish
to change and Select 'Propagation of Procurement Group': 'Propagage'.
The checkbox 'Auto-create Procurement Group' will then appear and you can
set it if you want to procurement group to be automatically created.

View File

@@ -0,0 +1,2 @@
* Jordi Ballester <jordi.ballester@eficent.com>
* Lois Rilo <lois.rilo@eficent.com>

View File

@@ -0,0 +1,9 @@
This module allows the system to propose automatically new procurement groups
when procuring.
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.

View File

@@ -0,0 +1,4 @@
#. Create a new procurement and make sure that it determines a pull rule
with the option 'Auto-create Procurement Group' set.
#. When the procurement rule is executed, a procurement group with
format 'PG/000001' will be created.

View File

@@ -1,4 +1 @@
# -*- coding: utf-8 -*-
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from . import test_auto_create

View File

@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-
# © 2017 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
@@ -8,53 +7,89 @@ from odoo.tests.common import TransactionCase
class TestProcurementAutoCreateGroup(TransactionCase):
def setUp(self, *args, **kwargs):
super(TestProcurementAutoCreateGroup, self).setUp(*args, **kwargs)
self.po_model = self.env['procurement.order']
self.pr_model = self.env['procurement.rule']
self.product_12 = self.env.ref('product.product_product_12')
# Needed to avoid the dependency with stock:
if self.env.registry.models.get('stock.picking'):
picking_type_id = self.env.ref('stock.picking_type_internal').id
else:
picking_type_id = False
self.group_obj = self.env['procurement.group']
self.rule_obj = self.env['procurement.rule']
self.route_obj = self.env['stock.location.route']
self.move_obj = self.env['stock.move']
self.product_obj = self.env['product.product']
# Create rules:
self.no_auto_create = self.pr_model.create({
'name': 'rule without autocreate',
'auto_create_group': False,
'action': [],
'picking_type_id': picking_type_id,
self.warehouse = self.env.ref('stock.warehouse0')
self.location = self.env.ref('stock.stock_location_stock')
loc_components = self.env.ref('stock.stock_location_components')
picking_type_id = self.env.ref('stock.picking_type_internal').id
# Create rules and routes:
route_auto = self.route_obj.create({
'name': 'Auto Create Group',
})
self.auto_create = self.pr_model.create({
self.rule_1 = self.rule_obj.create({
'name': 'rule with autocreate',
'route_id': route_auto.id,
'auto_create_group': True,
'action': [],
'action': 'move',
'warehouse_id': self.warehouse.id,
'picking_type_id': picking_type_id,
'location_id': self.location.id,
'location_src_id': loc_components.id,
})
route_no_auto = self.route_obj.create({
'name': 'Not Auto Create Group',
})
self.rule_obj.create({
'name': 'rule with no autocreate',
'route_id': route_no_auto.id,
'auto_create_group': False,
'action': 'move',
'warehouse_id': self.warehouse.id,
'picking_type_id': picking_type_id,
'location_id': self.location.id,
'location_src_id': loc_components.id,
})
def test_auto_create_group(self):
# Prepare products:
self.prod_auto = self.product_obj.create({
'name': 'Test Product 1',
'type': 'product',
'route_ids': [(6, 0, [route_auto.id])],
})
self.prod_no_auto = self.product_obj.create({
'name': 'Test Product 2',
'type': 'product',
'route_ids': [(6, 0, [route_no_auto.id])],
})
def _procure(self, product):
values = {}
self.group_obj.run(
product, 5.0, product.uom_id, self.location,
'TEST', 'odoo tests', values,
)
return True
def test_01_no_auto_create_group(self):
"""Test auto creation of group."""
proc1 = self.po_model.create({
'name': 'proc01',
'product_id': self.product_12.id,
'product_qty': 1.0,
'product_uom': self.product_12.uom_id.id,
'rule_id': self.no_auto_create.id,
})
self.assertFalse(proc1.group_id,
"Procurement Group should not have been assigned.")
proc2 = self.po_model.create({
'name': 'proc02',
'product_id': self.product_12.id,
'product_qty': 1.0,
'product_uom': self.product_12.uom_id.id,
'rule_id': self.auto_create.id,
})
self.assertTrue(proc2.group_id,
"Procurement Group has not been assigned.")
move = self.move_obj.search([
('product_id', '=', self.prod_no_auto.id)])
self.assertFalse(move)
self._procure(self.prod_no_auto)
move = self.move_obj.search([
('product_id', '=', self.prod_no_auto.id)])
self.assertTrue(move)
self.assertFalse(
move.group_id, "Procurement Group should not have been assigned.")
def test_onchange_method(self):
def test_02_auto_create_group(self):
move = self.move_obj.search([('product_id', '=', self.prod_auto.id)])
self.assertFalse(move)
self._procure(self.prod_auto)
move = self.move_obj.search([('product_id', '=', self.prod_auto.id)])
self.assertTrue(move)
self.assertTrue(move.group_id, "Procurement Group not assigned.")
def test_03_onchange_method(self):
"""Test onchange method for procurement rule."""
proc_rule = self.auto_create
proc_rule = self.rule_1
self.assertTrue(proc_rule.auto_create_group)
proc_rule.write({'group_propagation_option': 'none'})
proc_rule._onchange_group_propagation_option()
self.assertFalse(proc_rule.auto_create_group)

View File

@@ -2,10 +2,9 @@
<odoo>
<record model="ir.ui.view" id="view_procurement_rule_form">
<field name="name">procurement.rule.form</field>
<field name="name">procurement.rule.form - procurement_auto_create_group</field>
<field name="model">procurement.rule</field>
<field name="inherit_id"
ref="procurement.view_procurement_rule_form"/>
<field name="inherit_id" ref="stock.view_procurement_rule_form"/>
<field name="arch" type="xml">
<field name="group_propagation_option" position="after">
<field name="auto_create_group"