Skip to content

Commit

Permalink
[11.0][FIX] Consider *Qty Multiple* on product to propose the quantit…
Browse files Browse the repository at this point in the history
…y to procure.
  • Loading branch information
LoisRForgeFlow committed Aug 30, 2018
1 parent f286625 commit 95a6fde
Show file tree
Hide file tree
Showing 5 changed files with 111 additions and 8 deletions.
2 changes: 1 addition & 1 deletion mrp_multi_level/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
'name': 'MRP Multi Level',
'version': '11.0.1.0.1',
'version': '11.0.1.1.0',
'development_status': 'Beta',
'license': 'AGPL-3',
'author': 'Ucamco, '
Expand Down
15 changes: 9 additions & 6 deletions mrp_multi_level/models/mrp_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# © 2016-18 Eficent Business and IT Consulting Services S.L.
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from math import ceil

from odoo import api, fields, models


Expand Down Expand Up @@ -118,15 +120,16 @@ def _compute_main_supplier(self):

@api.multi
def _adjust_qty_to_order(self, qty_to_order):
# TODO: consider mrp_qty_multiple?
self.ensure_one()
if not self.mrp_maximum_order_qty and not self.mrp_minimum_order_qty:
if (not self.mrp_maximum_order_qty and not
self.mrp_minimum_order_qty and self.mrp_qty_multiple == 1.0):
return qty_to_order
if qty_to_order < self.mrp_minimum_order_qty:
return self.mrp_minimum_order_qty
if self.mrp_qty_multiple:
multiplier = ceil(qty_to_order / self.mrp_qty_multiple)
qty_to_order = multiplier * self.mrp_qty_multiple
if self.mrp_maximum_order_qty and qty_to_order > \
self.mrp_maximum_order_qty:
qty = self.mrp_maximum_order_qty
else:
qty = qty_to_order
return qty
return self.mrp_maximum_order_qty
return qty_to_order
6 changes: 6 additions & 0 deletions mrp_multi_level/readme/HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
11.0.1.1.0 (2018-08-30)
~~~~~~~~~~~~~~~~~~~~~~~

* [FIX] Consider *Qty Multiple* on product to propose the quantity to procure.
(`#297 <https://github.com/OCA/manufacture/pull/297>`_)

11.0.1.0.1 (2018-08-03)
~~~~~~~~~~~~~~~~~~~~~~~

Expand Down
2 changes: 2 additions & 0 deletions mrp_multi_level/readme/ROADMAP.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* The functionality related to field *Nbr. Days* in products is not
functional for the time being. Please, stay tuned to future updates.
94 changes: 93 additions & 1 deletion mrp_multi_level/tests/test_mrp_multi_level.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,38 @@ def setUpClass(cls):
'route_ids': [(6, 0, [route_buy])],
'seller_ids': [(0, 0, {'name': vendor1.id, 'price': 20.0})],
})
cls.prod_min = cls.product_obj.create({
'name': 'Product with minimum order qty',
'type': 'product',
'list_price': 50.0,
'route_ids': [(6, 0, [route_buy])],
'seller_ids': [(0, 0, {'name': vendor1.id, 'price': 10.0})],
'mrp_minimum_order_qty': 50.0,
'mrp_maximum_order_qty': 0.0,
'mrp_qty_multiple': 1.0,
})
cls.prod_max = cls.product_obj.create({
'name': 'Product with maximum order qty',
'type': 'product',
'list_price': 50.0,
'route_ids': [(6, 0, [route_buy])],
'seller_ids': [(0, 0, {'name': vendor1.id, 'price': 10.0})],
'mrp_minimum_order_qty': 50.0,
'mrp_maximum_order_qty': 100.0,
'mrp_qty_multiple': 1.0,
})
cls.prod_multiple = cls.product_obj.create({
'name': 'Product with qty multiple',
'type': 'product',
'list_price': 50.0,
'route_ids': [(6, 0, [route_buy])],
'seller_ids': [(0, 0, {'name': vendor1.id, 'price': 10.0})],
'mrp_minimum_order_qty': 50.0,
'mrp_maximum_order_qty': 500.0,
'mrp_qty_multiple': 25.0,
})

# Create test picking:
# Create test picking for FP-1 and FP-2:
res = cls.calendar.plan_days(7+1, datetime.today())
date_move = res.date()
cls.picking_1 = cls.stock_picking_obj.create({
Expand Down Expand Up @@ -86,6 +116,45 @@ def setUpClass(cls):
})
cls.picking_1.action_confirm()

# Create test picking for procure qty adjustment tests:
cls.picking_2 = cls.stock_picking_obj.create({
'picking_type_id': cls.env.ref('stock.picking_type_out').id,
'location_id': cls.stock_location.id,
'location_dest_id': cls.customer_location.id,
'move_lines': [
(0, 0, {
'name': 'Test move prod_min',
'product_id': cls.prod_min.id,
'date_expected': date_move,
'date': date_move,
'product_uom': cls.prod_min.uom_id.id,
'product_uom_qty': 16,
'location_id': cls.stock_location.id,
'location_dest_id': cls.customer_location.id
}),
(0, 0, {
'name': 'Test move prod_max',
'product_id': cls.prod_max.id,
'date_expected': date_move,
'date': date_move,
'product_uom': cls.prod_max.uom_id.id,
'product_uom_qty': 140,
'location_id': cls.stock_location.id,
'location_dest_id': cls.customer_location.id
}),
(0, 0, {
'name': 'Test move prod_multiple',
'product_id': cls.prod_multiple.id,
'date_expected': date_move,
'date': date_move,
'product_uom': cls.prod_multiple.uom_id.id,
'product_uom_qty': 112,
'location_id': cls.stock_location.id,
'location_dest_id': cls.customer_location.id
})]
})
cls.picking_2.action_confirm()

# Create Test PO:
date_po = cls.calendar.plan_days(1+1, datetime.today()).date()
cls.po = cls.po_obj.create({
Expand Down Expand Up @@ -372,5 +441,28 @@ def test_07_procure_mo(self):
mo_date_start = mos.date_planned_start.split(' ')[0]
self.assertEqual(mo_date_start, self.date_5)

def test_08__adjust_qty_to_order(self):
"""Test the adjustments made to the qty to procure when minimum,
maximum order quantities and quantity multiple are set."""
# minimum order quantity:
mrp_inv_min = self.mrp_inventory_obj.search([
('mrp_product_id.product_id', '=', self.prod_min.id)])
self.assertEqual(mrp_inv_min.to_procure, 50.0)
# maximum order quantity:
mrp_inv_max = self.mrp_inventory_obj.search([
('mrp_product_id.product_id', '=', self.prod_max.id)])
self.assertEqual(mrp_inv_max.to_procure, 150)
moves = self.mrp_move_obj.search([
('product_id', '=', self.prod_max.id),
('mrp_action', '!=', 'none'),
])
self.assertEqual(len(moves), 2)
self.assertIn(100.0, moves.mapped('mrp_qty'))
self.assertIn(50.0, moves.mapped('mrp_qty'))
# quantity multiple:
mrp_inv_multiple = self.mrp_inventory_obj.search([
('mrp_product_id.product_id', '=', self.prod_multiple.id)])
self.assertEqual(mrp_inv_multiple.to_procure, 125)

# TODO: test procure wizard: pos, multiple...
# TODO: test multiple destination IDS:...

0 comments on commit 95a6fde

Please sign in to comment.