mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[MIG] stock_orderpoint_uom: Migration to 13.0
This commit is contained in:
@@ -1,12 +1,11 @@
|
||||
# Copyright 2016-17 Eficent Business and IT Consulting Services S.L.
|
||||
# (http://www.eficent.com)
|
||||
# Copyright 2016-19 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
{
|
||||
"name": "Stock Orderpoint UoM",
|
||||
"summary": "Allows to create procurement orders in the UoM indicated in "
|
||||
"the orderpoint",
|
||||
"version": "12.0.1.1.0",
|
||||
"author": "Eficent, " "Odoo Community Association (OCA)",
|
||||
"version": "13.0.1.0.0",
|
||||
"author": "ForgeFlow, Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/stock-logistics-warehouse",
|
||||
"category": "Warehouse Management",
|
||||
"depends": ["purchase_stock"],
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
# Copyright (C) 2018 - TODAY, Open Source Integrators
|
||||
# (http://www.opensourceintegrators.com)
|
||||
# (http://www.opensourceintegrators.com)
|
||||
# Copyright 2019 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import api, models
|
||||
@@ -9,16 +10,40 @@ class ProcurementGroup(models.Model):
|
||||
_inherit = "procurement.group"
|
||||
|
||||
@api.model
|
||||
def run(
|
||||
self, product_id, product_qty, product_uom, location_id, name, origin, values
|
||||
):
|
||||
if "orderpoint_id" in values:
|
||||
orderpoint = values.get("orderpoint_id")
|
||||
if orderpoint.procure_uom_id and product_uom != orderpoint.procure_uom_id:
|
||||
product_qty = product_uom._compute_quantity(
|
||||
product_qty, orderpoint.procure_uom_id
|
||||
)
|
||||
product_uom = orderpoint.procure_uom_id
|
||||
return super(ProcurementGroup, self).run(
|
||||
product_id, product_qty, product_uom, location_id, name, origin, values
|
||||
)
|
||||
def run(self, procurements):
|
||||
# 'Procurement' is a 'namedtuple', which is not editable.
|
||||
# The 'procurement' which needs to be edited is created new
|
||||
# and the previous one is deleted.
|
||||
Proc = self.env["procurement.group"].Procurement
|
||||
indexes_to_pop = []
|
||||
new_procs = []
|
||||
for i, procurement in enumerate(procurements):
|
||||
if "orderpoint_id" in procurement.values:
|
||||
orderpoint = procurement.values.get("orderpoint_id")
|
||||
if (
|
||||
orderpoint.procure_uom_id
|
||||
and procurement.product_uom != orderpoint.procure_uom_id
|
||||
):
|
||||
new_product_qty = procurement.product_uom._compute_quantity(
|
||||
procurement.product_qty, orderpoint.procure_uom_id
|
||||
)
|
||||
new_product_uom = orderpoint.procure_uom_id
|
||||
new_procs.append(
|
||||
Proc(
|
||||
procurement.product_id,
|
||||
new_product_qty,
|
||||
new_product_uom,
|
||||
procurement.location_id,
|
||||
procurement.name,
|
||||
procurement.origin,
|
||||
procurement.company_id,
|
||||
procurement.values,
|
||||
)
|
||||
)
|
||||
indexes_to_pop.append(i)
|
||||
if new_procs:
|
||||
indexes_to_pop.reverse()
|
||||
for index in indexes_to_pop:
|
||||
procurements.pop(index)
|
||||
procurements.extend(new_procs)
|
||||
return super(ProcurementGroup, self).run(procurements)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# Copyright 2018 Eficent Business and IT Consulting Services S.L.
|
||||
# (http://www.eficent.com)
|
||||
# Copyright 2016-19 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import _, api, models
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
# Copyright 2016-17 Eficent Business and IT Consulting Services S.L.
|
||||
# (http://www.eficent.com)
|
||||
# Copyright 2016-19 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
from odoo import _, api, fields, models
|
||||
from odoo.exceptions import UserError
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class Orderpoint(models.Model):
|
||||
@@ -20,7 +19,7 @@ class Orderpoint(models.Model):
|
||||
!= orderpoint.procure_uom_id.category_id
|
||||
for orderpoint in self
|
||||
):
|
||||
raise UserError(
|
||||
raise ValidationError(
|
||||
_(
|
||||
"Error: The product default Unit of Measure and "
|
||||
"the procurement Unit of Measure must be in the "
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
* Jordi Ballester Alomar <jordi.ballester@eficent.com>
|
||||
* Lois Rilo <lois.rilo@eficent.com>
|
||||
* Jordi Ballester Alomar <jordi.ballester@forgeflow.com>
|
||||
* Lois Rilo <lois.rilo@forgeflow.com>
|
||||
* Bhavesh Odedra <bodedra@opensourceintegrators.com>
|
||||
* Kitti Upariphutthiphong <kittiu@ecosoft.co.th>
|
||||
* Joan Sisquella <joan.sisquella@forgeflow.com>
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# Copyright 2016-17 Eficent Business and IT Consulting Services S.L.
|
||||
# (http://www.eficent.com)
|
||||
# Copyright 2016-19 ForgeFlow S.L. (https://www.forgeflow.com)
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import odoo.tests.common as common
|
||||
@@ -46,7 +45,7 @@ class TestStockOrderpointProcureUom(common.TransactionCase):
|
||||
}
|
||||
)
|
||||
|
||||
def test_stock_orderpoint_procure_uom(self):
|
||||
def test_01_stock_orderpoint_procure_uom(self):
|
||||
|
||||
orderpoint = self.env["stock.warehouse.orderpoint"].create(
|
||||
{
|
||||
@@ -72,7 +71,7 @@ class TestStockOrderpointProcureUom(common.TransactionCase):
|
||||
self.assertEqual(purchase_line.product_uom, self.uom_dozen)
|
||||
self.assertEqual(purchase_line.product_qty, 2)
|
||||
|
||||
def test_stock_orderpoint_wrong_uom(self):
|
||||
def test_02_stock_orderpoint_wrong_uom(self):
|
||||
|
||||
with mute_logger("openerp.sql_db"):
|
||||
with self.assertRaises(ValidationError):
|
||||
@@ -87,7 +86,7 @@ class TestStockOrderpointProcureUom(common.TransactionCase):
|
||||
}
|
||||
)
|
||||
|
||||
def test_regenerate_po(self):
|
||||
def test_03_regenerate_po(self):
|
||||
def _assert_purchase_generated(self, supplier, product):
|
||||
purchase = self.purchase_model.search([("partner_id", "=", supplier.id)])
|
||||
self.assertEquals(len(purchase), 1)
|
||||
@@ -99,7 +98,7 @@ class TestStockOrderpointProcureUom(common.TransactionCase):
|
||||
return purchase
|
||||
|
||||
supplier = self.env["res.partner"].create(
|
||||
{"name": "Brewery Inc", "is_company": True, "supplier": True}
|
||||
{"name": "Brewery Inc", "is_company": True}
|
||||
)
|
||||
|
||||
product = self.env["product.product"].create(
|
||||
|
||||
@@ -19,9 +19,11 @@
|
||||
<field name="inherit_id"
|
||||
ref="stock.view_warehouse_orderpoint_form"/>
|
||||
<field name="arch" type="xml">
|
||||
<field name="product_uom" position="after">
|
||||
<field name="procure_uom_id" class="oe_inline"
|
||||
groups="uom.group_uom"/>
|
||||
<field name="product_id" position="after">
|
||||
<field name="procure_uom_id" class="oe_inline" groups="uom.group_uom"/>
|
||||
</field>
|
||||
<field name="qty_multiple" position="after">
|
||||
<p class="oe_grey">Quantity Multiple is applied to the base UoM.</p>
|
||||
</field>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user