mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
procurement_auto_create_group: Set partner on created procurement group
This commit is contained in:
committed by
Laurent Mignon (ACSONE)
parent
01664cbdeb
commit
c1dce6e377
@@ -84,6 +84,7 @@ Contributors
|
||||
* Jordi Ballester <jordi.ballester@forgeflow.com>
|
||||
* Lois Rilo <lois.rilo@forgeflow.com>
|
||||
* Héctor Villarreal Ortega <hector.villarreal@forgeflow.com>
|
||||
* Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
|
||||
|
||||
Maintainers
|
||||
~~~~~~~~~~~
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
# Copyright 2017-2020 ForgeFlow, S.L.
|
||||
# Copyright 2021 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
{
|
||||
"name": "Procurement Auto Create Group",
|
||||
"version": "14.0.1.0.0",
|
||||
"version": "14.0.1.1.0",
|
||||
"development_status": "Production/Stable",
|
||||
"license": "AGPL-3",
|
||||
"summary": "Allows to configure the system to propose automatically new "
|
||||
"procurement groups during the procurement run.",
|
||||
"author": "ForgeFlow," "Odoo Community Association (OCA)",
|
||||
"author": "ForgeFlow, BCIM, Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/stock-logistics-warehouse",
|
||||
"category": "Warehouse",
|
||||
"depends": ["stock"],
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
# Copyright 2017-2020 ForgeFlow, S.L.
|
||||
# Copyright 2021 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import _, api, models
|
||||
from odoo.exceptions import UserError
|
||||
from odoo import api, models
|
||||
|
||||
|
||||
class ProcurementGroup(models.Model):
|
||||
@@ -10,25 +10,16 @@ class ProcurementGroup(models.Model):
|
||||
|
||||
@api.model
|
||||
def _get_rule(self, product_id, location_id, values):
|
||||
result = super()._get_rule(product_id, location_id, values)
|
||||
rule = 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
|
||||
rule
|
||||
and not values.get("group_id")
|
||||
and result.auto_create_group
|
||||
and rule.auto_create_group
|
||||
and values.get("date_planned")
|
||||
):
|
||||
group_data = self._prepare_auto_procurement_group_data()
|
||||
group_data = rule._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):
|
||||
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,
|
||||
}
|
||||
return rule
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
# Copyright 2017-2020 ForgeFlow, S.L.
|
||||
# Copyright 2021 Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import api, fields, models
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
|
||||
|
||||
class StockRule(models.Model):
|
||||
@@ -13,3 +15,12 @@ class StockRule(models.Model):
|
||||
def _onchange_group_propagation_option(self):
|
||||
if self.group_propagation_option != "propagate":
|
||||
self.auto_create_group = False
|
||||
|
||||
def _prepare_auto_procurement_group_data(self):
|
||||
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,
|
||||
"partner_id": self.partner_address_id.id,
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
* Jordi Ballester <jordi.ballester@forgeflow.com>
|
||||
* Lois Rilo <lois.rilo@forgeflow.com>
|
||||
* Héctor Villarreal Ortega <hector.villarreal@forgeflow.com>
|
||||
* Jacques-Etienne Baudoux (BCIM) <je@bcim.be>
|
||||
|
||||
@@ -18,6 +18,8 @@ class TestProcurementAutoCreateGroup(TransactionCase):
|
||||
loc_components = self.env.ref("stock.stock_location_components")
|
||||
picking_type_id = self.env.ref("stock.picking_type_internal").id
|
||||
|
||||
self.partner = self.env["res.partner"].create({"name": "Partner"})
|
||||
|
||||
# Create rules and routes:
|
||||
route_auto = self.route_obj.create({"name": "Auto Create Group"})
|
||||
self.rule_1 = self.rule_obj.create(
|
||||
@@ -30,6 +32,7 @@ class TestProcurementAutoCreateGroup(TransactionCase):
|
||||
"picking_type_id": picking_type_id,
|
||||
"location_id": self.location.id,
|
||||
"location_src_id": loc_components.id,
|
||||
"partner_address_id": self.partner.id,
|
||||
}
|
||||
)
|
||||
route_no_auto = self.route_obj.create({"name": "Not Auto Create Group"})
|
||||
@@ -98,6 +101,11 @@ class TestProcurementAutoCreateGroup(TransactionCase):
|
||||
move = self.move_obj.search([("product_id", "=", self.prod_auto.id)])
|
||||
self.assertTrue(move)
|
||||
self.assertTrue(move.group_id, "Procurement Group not assigned.")
|
||||
self.assertEqual(
|
||||
move.group_id.partner_id,
|
||||
self.partner,
|
||||
"Procurement Group partner missing.",
|
||||
)
|
||||
|
||||
def test_03_onchange_method(self):
|
||||
"""Test onchange method for stock rule."""
|
||||
|
||||
Reference in New Issue
Block a user