mirror of
https://github.com/OCA/stock-logistics-warehouse.git
synced 2025-01-21 14:27:28 +02:00
[IMP] stock_orderpoint_uom: black, isort
This commit is contained in:
committed by
davidborromeo
parent
2e2dc0267b
commit
a784784eaf
@@ -4,15 +4,14 @@
|
||||
{
|
||||
"name": "Stock Orderpoint UoM",
|
||||
"summary": "Allows to create procurement orders in the UoM indicated in "
|
||||
"the orderpoint",
|
||||
"the orderpoint",
|
||||
"version": "12.0.1.1.0",
|
||||
"author": "Eficent, "
|
||||
"Odoo Community Association (OCA)",
|
||||
"author": "Eficent, " "Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/stock-logistics-warehouse",
|
||||
"category": "Warehouse Management",
|
||||
"depends": ["purchase_stock"],
|
||||
"data": ["views/stock_warehouse_orderpoint_view.xml"],
|
||||
"license": "AGPL-3",
|
||||
'installable': True,
|
||||
'application': False,
|
||||
"installable": True,
|
||||
"application": False,
|
||||
}
|
||||
|
||||
@@ -9,15 +9,16 @@ 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:
|
||||
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_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)
|
||||
return super(ProcurementGroup, self).run(
|
||||
product_id, product_qty, product_uom, location_id, name, origin, values
|
||||
)
|
||||
|
||||
@@ -2,21 +2,27 @@
|
||||
# (http://www.eficent.com)
|
||||
# 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 ProductTemplate(models.Model):
|
||||
_inherit = "product.template"
|
||||
|
||||
@api.constrains('uom_id')
|
||||
@api.constrains("uom_id")
|
||||
def _check_orderpoint_procure_uom(self):
|
||||
for rec in self:
|
||||
orderpoint = self.env['stock.warehouse.orderpoint'].search([
|
||||
('procure_uom_id.category_id', '!=',
|
||||
rec.uom_id.category_id.id),
|
||||
('product_id', 'in', rec.product_variant_ids.ids)], limit=1)
|
||||
orderpoint = self.env["stock.warehouse.orderpoint"].search(
|
||||
[
|
||||
("procure_uom_id.category_id", "!=", rec.uom_id.category_id.id),
|
||||
("product_id", "in", rec.product_variant_ids.ids),
|
||||
],
|
||||
limit=1,
|
||||
)
|
||||
if orderpoint:
|
||||
raise UserError(
|
||||
_("At least one reordering rule for this product has a "
|
||||
"different Procurement unit of measure category."))
|
||||
_(
|
||||
"At least one reordering rule for this product has a "
|
||||
"different Procurement unit of measure category."
|
||||
)
|
||||
)
|
||||
|
||||
@@ -2,25 +2,29 @@
|
||||
# (http://www.eficent.com)
|
||||
# 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 Orderpoint(models.Model):
|
||||
_inherit = "stock.warehouse.orderpoint"
|
||||
|
||||
procure_uom_id = fields.Many2one(comodel_name='uom.uom',
|
||||
string="Procurement UoM")
|
||||
procure_uom_id = fields.Many2one(comodel_name="uom.uom", string="Procurement UoM")
|
||||
|
||||
@api.constrains('product_id', 'procure_uom_id')
|
||||
@api.constrains("product_id", "procure_uom_id")
|
||||
def _check_procure_uom(self):
|
||||
if any(orderpoint.product_uom and
|
||||
orderpoint.procure_uom_id and
|
||||
orderpoint.product_uom.category_id !=
|
||||
orderpoint.procure_uom_id.category_id
|
||||
for orderpoint in self):
|
||||
raise UserError(
|
||||
_('Error: The product default Unit of Measure and '
|
||||
'the procurement Unit of Measure must be in the '
|
||||
'same category.'))
|
||||
if any(
|
||||
orderpoint.product_uom
|
||||
and orderpoint.procure_uom_id
|
||||
and orderpoint.product_uom.category_id
|
||||
!= orderpoint.procure_uom_id.category_id
|
||||
for orderpoint in self
|
||||
):
|
||||
raise UserError(
|
||||
_(
|
||||
"Error: The product default Unit of Measure and "
|
||||
"the procurement Unit of Measure must be in the "
|
||||
"same category."
|
||||
)
|
||||
)
|
||||
return True
|
||||
|
||||
@@ -3,62 +3,70 @@
|
||||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
||||
|
||||
import odoo.tests.common as common
|
||||
from odoo.tools import mute_logger
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
|
||||
class TestStockOrderpointProcureUom(common.TransactionCase):
|
||||
|
||||
def setUp(self):
|
||||
super(TestStockOrderpointProcureUom, self).setUp()
|
||||
|
||||
# Get required Model
|
||||
productObj = self.env['product.product']
|
||||
self.purchase_model = self.env['purchase.order']
|
||||
self.purchase_line_model = self.env['purchase.order.line']
|
||||
self.warehouse = self.env.ref('stock.warehouse0')
|
||||
self.location_stock = self.env.ref('stock.stock_location_stock')
|
||||
self.uom_unit = self.env.ref('uom.product_uom_unit')
|
||||
productObj = self.env["product.product"]
|
||||
self.purchase_model = self.env["purchase.order"]
|
||||
self.purchase_line_model = self.env["purchase.order.line"]
|
||||
self.warehouse = self.env.ref("stock.warehouse0")
|
||||
self.location_stock = self.env.ref("stock.stock_location_stock")
|
||||
self.uom_unit = self.env.ref("uom.product_uom_unit")
|
||||
self.uom_unit.rounding = 1
|
||||
self.uom_dozen = self.env.ref('uom.product_uom_dozen')
|
||||
self.uom_dozen = self.env.ref("uom.product_uom_dozen")
|
||||
self.uom_dozen.rounding = 1
|
||||
self.uom_kg = self.env.ref('uom.product_uom_kgm')
|
||||
self.uom_kg = self.env.ref("uom.product_uom_kgm")
|
||||
|
||||
self.productA = productObj.create(
|
||||
{'name': 'product A',
|
||||
'standard_price': 1,
|
||||
'type': 'product',
|
||||
'uom_id': self.uom_unit.id,
|
||||
'uom_po_id': self.uom_dozen.id,
|
||||
'default_code': 'A',
|
||||
'variant_seller_ids': [(0, 0, {
|
||||
'name': self.env.ref('base.res_partner_3').id,
|
||||
'delay': 3,
|
||||
'min_qty': 1,
|
||||
'price': 72,
|
||||
})],
|
||||
})
|
||||
{
|
||||
"name": "product A",
|
||||
"standard_price": 1,
|
||||
"type": "product",
|
||||
"uom_id": self.uom_unit.id,
|
||||
"uom_po_id": self.uom_dozen.id,
|
||||
"default_code": "A",
|
||||
"variant_seller_ids": [
|
||||
(
|
||||
0,
|
||||
0,
|
||||
{
|
||||
"name": self.env.ref("base.res_partner_3").id,
|
||||
"delay": 3,
|
||||
"min_qty": 1,
|
||||
"price": 72,
|
||||
},
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
def test_stock_orderpoint_procure_uom(self):
|
||||
|
||||
orderpoint = self.env['stock.warehouse.orderpoint'].create({
|
||||
'warehouse_id': self.warehouse.id,
|
||||
'location_id': self.location_stock.id,
|
||||
'product_id': self.productA.id,
|
||||
'product_max_qty': 24,
|
||||
'product_min_qty': 12,
|
||||
'product_uom': self.uom_unit.id,
|
||||
'procure_uom_id': self.uom_dozen.id,
|
||||
})
|
||||
orderpoint = self.env["stock.warehouse.orderpoint"].create(
|
||||
{
|
||||
"warehouse_id": self.warehouse.id,
|
||||
"location_id": self.location_stock.id,
|
||||
"product_id": self.productA.id,
|
||||
"product_max_qty": 24,
|
||||
"product_min_qty": 12,
|
||||
"product_uom": self.uom_unit.id,
|
||||
"procure_uom_id": self.uom_dozen.id,
|
||||
}
|
||||
)
|
||||
|
||||
self.env['procurement.group'].run_scheduler()
|
||||
self.env["procurement.group"].run_scheduler()
|
||||
# As per route configuration, it will create Purchase order
|
||||
purchase = self.purchase_model.search(
|
||||
[('origin', 'ilike', orderpoint.name)])
|
||||
purchase = self.purchase_model.search([("origin", "ilike", orderpoint.name)])
|
||||
self.assertEquals(len(purchase), 1)
|
||||
purchase_line = self.purchase_line_model.search(
|
||||
[('orderpoint_id', '=', orderpoint.id),
|
||||
('order_id', '=', purchase.id)])
|
||||
[("orderpoint_id", "=", orderpoint.id), ("order_id", "=", purchase.id)]
|
||||
)
|
||||
self.assertEquals(len(purchase_line), 1)
|
||||
self.assertEqual(purchase_line.product_id, self.productA)
|
||||
self.assertEqual(purchase_line.product_uom, self.uom_dozen)
|
||||
@@ -66,22 +74,22 @@ class TestStockOrderpointProcureUom(common.TransactionCase):
|
||||
|
||||
def test_stock_orderpoint_wrong_uom(self):
|
||||
|
||||
with mute_logger('openerp.sql_db'):
|
||||
with mute_logger("openerp.sql_db"):
|
||||
with self.assertRaises(ValidationError):
|
||||
self.env['stock.warehouse.orderpoint'].create({
|
||||
'warehouse_id': self.warehouse.id,
|
||||
'location_id': self.location_stock.id,
|
||||
'product_id': self.productA.id,
|
||||
'product_max_qty': 24,
|
||||
'product_min_qty': 12,
|
||||
'procure_uom_id': self.uom_kg.id,
|
||||
})
|
||||
self.env["stock.warehouse.orderpoint"].create(
|
||||
{
|
||||
"warehouse_id": self.warehouse.id,
|
||||
"location_id": self.location_stock.id,
|
||||
"product_id": self.productA.id,
|
||||
"product_max_qty": 24,
|
||||
"product_min_qty": 12,
|
||||
"procure_uom_id": self.uom_kg.id,
|
||||
}
|
||||
)
|
||||
|
||||
def test_regenerate_po(self):
|
||||
|
||||
def _assert_purchase_generated(self, supplier, product):
|
||||
purchase = self.purchase_model.search(
|
||||
[('partner_id', '=', supplier.id)])
|
||||
purchase = self.purchase_model.search([("partner_id", "=", supplier.id)])
|
||||
self.assertEquals(len(purchase), 1)
|
||||
lines = purchase.order_line
|
||||
self.assertEquals(len(lines), 1)
|
||||
@@ -90,43 +98,46 @@ class TestStockOrderpointProcureUom(common.TransactionCase):
|
||||
self.assertEquals(lines.product_qty, 9)
|
||||
return purchase
|
||||
|
||||
supplier = self.env['res.partner'].create({
|
||||
'name': 'Brewery Inc',
|
||||
'is_company': True,
|
||||
'supplier': True
|
||||
})
|
||||
supplier = self.env["res.partner"].create(
|
||||
{"name": "Brewery Inc", "is_company": True, "supplier": True}
|
||||
)
|
||||
|
||||
product = self.env['product.product'].create({
|
||||
'name': 'Beer bottle',
|
||||
'standard_price': 1,
|
||||
'type': 'product',
|
||||
'uom_id': self.uom_unit.id,
|
||||
'uom_po_id': self.uom_dozen.id,
|
||||
'seller_ids': [(0, False, {
|
||||
'name': supplier.id,
|
||||
'delay': 1,
|
||||
'min_qty': 1,
|
||||
'price': 2
|
||||
})]
|
||||
})
|
||||
product = self.env["product.product"].create(
|
||||
{
|
||||
"name": "Beer bottle",
|
||||
"standard_price": 1,
|
||||
"type": "product",
|
||||
"uom_id": self.uom_unit.id,
|
||||
"uom_po_id": self.uom_dozen.id,
|
||||
"seller_ids": [
|
||||
(
|
||||
0,
|
||||
False,
|
||||
{"name": supplier.id, "delay": 1, "min_qty": 1, "price": 2},
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
|
||||
self.env['stock.warehouse.orderpoint'].create({
|
||||
'warehouse_id': self.warehouse.id,
|
||||
'location_id': self.location_stock.id,
|
||||
'product_id': product.id,
|
||||
'product_max_qty': 100,
|
||||
'product_min_qty': 10,
|
||||
'qty_multiple': 10,
|
||||
'product_uom': self.uom_unit.id,
|
||||
'procure_uom_id': self.uom_dozen.id,
|
||||
})
|
||||
self.env["stock.warehouse.orderpoint"].create(
|
||||
{
|
||||
"warehouse_id": self.warehouse.id,
|
||||
"location_id": self.location_stock.id,
|
||||
"product_id": product.id,
|
||||
"product_max_qty": 100,
|
||||
"product_min_qty": 10,
|
||||
"qty_multiple": 10,
|
||||
"product_uom": self.uom_unit.id,
|
||||
"procure_uom_id": self.uom_dozen.id,
|
||||
}
|
||||
)
|
||||
|
||||
self.env['procurement.group'].run_scheduler()
|
||||
self.env["procurement.group"].run_scheduler()
|
||||
|
||||
purchase1 = _assert_purchase_generated(self, supplier, product)
|
||||
purchase1.button_cancel()
|
||||
purchase1.unlink()
|
||||
|
||||
self.env['procurement.group'].run_scheduler()
|
||||
self.env["procurement.group"].run_scheduler()
|
||||
|
||||
_assert_purchase_generated(self, supplier, product)
|
||||
|
||||
Reference in New Issue
Block a user