mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] procurement_auto_create_group: black, isort, prettier
This commit is contained in:
committed by
davidborromeo
parent
f5a0713073
commit
12599b0a87
@@ -6,16 +6,11 @@
|
||||
"development_status": "Production/Stable",
|
||||
"license": "AGPL-3",
|
||||
"summary": "Allows to configure the system to propose automatically new "
|
||||
"procurement groups during the procurement run.",
|
||||
"author": "Eficent,"
|
||||
"Odoo Community Association (OCA)",
|
||||
"procurement groups during the procurement run.",
|
||||
"author": "Eficent," "Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/stock-logistics-warehouse",
|
||||
"category": "Warehouse",
|
||||
"depends": [
|
||||
"stock",
|
||||
],
|
||||
"data": [
|
||||
'views/procurement_view.xml',
|
||||
],
|
||||
"depends": ["stock"],
|
||||
"data": ["views/procurement_view.xml"],
|
||||
"installable": True,
|
||||
}
|
||||
|
||||
@@ -1,31 +1,34 @@
|
||||
# Copyright 2017 Eficent Business and IT Consulting Services, S.L.
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import api, models, _
|
||||
from odoo import _, api, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class ProcurementGroup(models.Model):
|
||||
_inherit = 'procurement.group'
|
||||
_inherit = "procurement.group"
|
||||
|
||||
@api.model
|
||||
def _get_rule(self, product_id, location_id, values):
|
||||
result = super()._get_rule(product_id, location_id, values)
|
||||
# If there isn't a date planned in the values it means that this
|
||||
# method has been called outside of a procurement process.
|
||||
if result and not values.get('group_id') and result.auto_create_group \
|
||||
and values.get("date_planned"):
|
||||
if (
|
||||
result
|
||||
and not values.get("group_id")
|
||||
and result.auto_create_group
|
||||
and values.get("date_planned")
|
||||
):
|
||||
group_data = self._prepare_auto_procurement_group_data()
|
||||
group = self.env['procurement.group'].create(group_data)
|
||||
values['group_id'] = group
|
||||
group = self.env["procurement.group"].create(group_data)
|
||||
values["group_id"] = group
|
||||
return result
|
||||
|
||||
@api.model
|
||||
def _prepare_auto_procurement_group_data(self):
|
||||
name = self.env['ir.sequence'].next_by_code(
|
||||
'procurement.group') or False
|
||||
name = self.env["ir.sequence"].next_by_code("procurement.group") or False
|
||||
if not name:
|
||||
raise UserError(_('No sequence defined for procurement group.'))
|
||||
raise UserError(_("No sequence defined for procurement group."))
|
||||
return {
|
||||
'name': name,
|
||||
"name": name,
|
||||
}
|
||||
|
||||
@@ -5,11 +5,11 @@ from odoo import api, fields, models
|
||||
|
||||
|
||||
class StockRule(models.Model):
|
||||
_inherit = 'stock.rule'
|
||||
_inherit = "stock.rule"
|
||||
|
||||
auto_create_group = fields.Boolean(string='Auto-create Procurement Group')
|
||||
auto_create_group = fields.Boolean(string="Auto-create Procurement Group")
|
||||
|
||||
@api.onchange('group_propagation_option')
|
||||
@api.onchange("group_propagation_option")
|
||||
def _onchange_group_propagation_option(self):
|
||||
if self.group_propagation_option != 'propagate':
|
||||
if self.group_propagation_option != "propagate":
|
||||
self.auto_create_group = False
|
||||
|
||||
@@ -5,85 +5,86 @@ from odoo.tests.common import TransactionCase
|
||||
|
||||
|
||||
class TestProcurementAutoCreateGroup(TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestProcurementAutoCreateGroup, self).setUp()
|
||||
self.group_obj = self.env['procurement.group']
|
||||
self.rule_obj = self.env['stock.rule']
|
||||
self.route_obj = self.env['stock.location.route']
|
||||
self.move_obj = self.env['stock.move']
|
||||
self.product_obj = self.env['product.product']
|
||||
self.group_obj = self.env["procurement.group"]
|
||||
self.rule_obj = self.env["stock.rule"]
|
||||
self.route_obj = self.env["stock.location.route"]
|
||||
self.move_obj = self.env["stock.move"]
|
||||
self.product_obj = self.env["product.product"]
|
||||
|
||||
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
|
||||
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.rule_1 = self.rule_obj.create({
|
||||
'name': 'rule with autocreate',
|
||||
'route_id': route_auto.id,
|
||||
'auto_create_group': True,
|
||||
'action': 'pull_push',
|
||||
'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': 'pull_push',
|
||||
'warehouse_id': self.warehouse.id,
|
||||
'picking_type_id': picking_type_id,
|
||||
'location_id': self.location.id,
|
||||
'location_src_id': loc_components.id,
|
||||
})
|
||||
route_auto = self.route_obj.create({"name": "Auto Create Group"})
|
||||
self.rule_1 = self.rule_obj.create(
|
||||
{
|
||||
"name": "rule with autocreate",
|
||||
"route_id": route_auto.id,
|
||||
"auto_create_group": True,
|
||||
"action": "pull_push",
|
||||
"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": "pull_push",
|
||||
"warehouse_id": self.warehouse.id,
|
||||
"picking_type_id": picking_type_id,
|
||||
"location_id": self.location.id,
|
||||
"location_src_id": loc_components.id,
|
||||
}
|
||||
)
|
||||
|
||||
# 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])],
|
||||
})
|
||||
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,
|
||||
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."""
|
||||
move = self.move_obj.search([
|
||||
('product_id', '=', self.prod_no_auto.id)])
|
||||
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)])
|
||||
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.")
|
||||
move.group_id, "Procurement Group should not have been assigned."
|
||||
)
|
||||
|
||||
def test_02_auto_create_group(self):
|
||||
move = self.move_obj.search([('product_id', '=', self.prod_auto.id)])
|
||||
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)])
|
||||
move = self.move_obj.search([("product_id", "=", self.prod_auto.id)])
|
||||
self.assertTrue(move)
|
||||
self.assertTrue(move.group_id, "Procurement Group not assigned.")
|
||||
|
||||
@@ -91,6 +92,6 @@ class TestProcurementAutoCreateGroup(TransactionCase):
|
||||
"""Test onchange method for stock rule."""
|
||||
proc_rule = self.rule_1
|
||||
self.assertTrue(proc_rule.auto_create_group)
|
||||
proc_rule.write({'group_propagation_option': 'none'})
|
||||
proc_rule.write({"group_propagation_option": "none"})
|
||||
proc_rule._onchange_group_propagation_option()
|
||||
self.assertFalse(proc_rule.auto_create_group)
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<odoo>
|
||||
|
||||
<record model="ir.ui.view" id="view_stock_rule_form">
|
||||
<field name="name">stock.rule.form - procurement_auto_create_group</field>
|
||||
<field name="model">stock.rule</field>
|
||||
<field name="inherit_id" ref="stock.view_stock_rule_form"/>
|
||||
<field name="inherit_id" ref="stock.view_stock_rule_form" />
|
||||
<field name="arch" type="xml">
|
||||
<field name="group_propagation_option" position="after">
|
||||
<field name="auto_create_group"
|
||||
attrs="{'invisible':[('group_propagation_option','!=','propagate')]}"/>
|
||||
<field
|
||||
name="auto_create_group"
|
||||
attrs="{'invisible':[('group_propagation_option','!=','propagate')]}"
|
||||
/>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
|
||||
Reference in New Issue
Block a user