Skip to content

Commit

Permalink
[MIG] sale_order_lot_selection: Migration to 17.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderlienaerts committed Aug 2, 2024
1 parent e3582fe commit 8f1fbb9
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 61 deletions.
1 change: 1 addition & 0 deletions sale_order_lot_selection/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ Contributors
- Bhavesh Odedra <[email protected]>
- François Honoré <[email protected]>
- Florian da Costa <[email protected]>
- Sander Lienaerts <[email protected]>

Maintainers
-----------
Expand Down
4 changes: 2 additions & 2 deletions sale_order_lot_selection/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "Sale Order Lot Selection",
"version": "16.0.1.0.1",
"version": "17.0.1.0.0",
"category": "Sales Management",
"author": "Odoo Community Association (OCA), Agile Business Group",
"website": "https://github.com/OCA/sale-workflow",
"license": "AGPL-3",
"depends": ["sale_stock", "stock_restrict_lot"],
"data": ["view/sale_view.xml"],
"data": ["views/sale_order_views.xml"],
"demo": ["demo/sale_demo.xml"],
"maintainers": ["bodedra"],
"installable": True,
Expand Down
16 changes: 8 additions & 8 deletions sale_order_lot_selection/demo/sale_demo.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="lot_cable" model="stock.lot">
<record id="lot_cable_demo" model="stock.lot">
<field name="product_id" ref="stock.product_cable_management_box" />
<field name="name">cbl mng</field>
<field name="company_id" ref="base.main_company" />
</record>

<record id="sale1" model="sale.order">
<record id="sale_order_demo" model="sale.order">
<field name="partner_id" ref="base.res_partner_1" />
<field name="user_id" ref="base.user_admin" />
</record>

<record id="sol1" model="sale.order.line">
<field name="order_id" ref="sale_order_lot_selection.sale1" />
<record id="sale_order_line_1_demo" model="sale.order.line">
<field name="order_id" ref="sale_order_lot_selection.sale_order_demo" />
<field name="product_id" ref="stock.product_cable_management_box" />
<field name="product_uom_qty">1</field>
<field name="lot_id" ref="sale_order_lot_selection.lot_cable" />
<field name="lot_id" ref="sale_order_lot_selection.lot_cable_demo" />
</record>
<record id="sol2" model="sale.order.line">
<field name="order_id" ref="sale_order_lot_selection.sale1" />
<record id="sale_order_line_2_demo" model="sale.order.line">
<field name="order_id" ref="sale_order_lot_selection.sale_order_demo" />
<field name="product_id" ref="stock.product_cable_management_box" />
<field name="product_uom_qty">1</field>
<field name="lot_id" ref="sale_order_lot_selection.lot_cable" />
<field name="lot_id" ref="sale_order_lot_selection.lot_cable_demo" />
</record>

</odoo>
1 change: 1 addition & 0 deletions sale_order_lot_selection/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
- Bhavesh Odedra \<<[email protected]>\>
- François Honoré \<<[email protected]>\>
- Florian da Costa \<<[email protected]>\>
- Sander Lienaerts \<<[email protected]>\>
1 change: 1 addition & 0 deletions sale_order_lot_selection/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>Bhavesh Odedra &lt;<a class="reference external" href="mailto:bodedra&#64;opensourceintegrators.com">bodedra&#64;opensourceintegrators.com</a>&gt;</li>
<li>François Honoré &lt;<a class="reference external" href="mailto:francois.honore&#64;acsone.eu">francois.honore&#64;acsone.eu</a>&gt;</li>
<li>Florian da Costa &lt;<a class="reference external" href="mailto:florian.dacosta&#64;akretion.com">florian.dacosta&#64;akretion.com</a>&gt;</li>
<li>Sander Lienaerts &lt;<a class="reference external" href="mailto:sander.lienaerts&#64;codeforward.nl">sander.lienaerts&#64;codeforward.nl</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
97 changes: 46 additions & 51 deletions sale_order_lot_selection/tests/test_sale_order_lot_selection.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
# © 2015 Agile Business Group
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

import odoo.tests.common as test_common
from odoo.tests import TransactionCase


class TestSaleOrderLotSelection(test_common.SingleTransactionCase):
def setUp(self):
class TestSaleOrderLotSelection(TransactionCase):
@classmethod
def setUpClass(cls):
"""
Set up a sale order a particular lot.
Expand All @@ -16,34 +17,34 @@ def setUp(self):
I confirm it, transfer the delivery order and check lots on picking
"""
super(TestSaleOrderLotSelection, self).setUp()
self.prd_cable = self.env.ref("stock.product_cable_management_box")
self.prd_cable.tracking = "lot"
self.product_46 = self.env.ref("product.product_product_13")
self.product_12 = self.env.ref("product.product_product_12")
self.supplier_location = self.env.ref("stock.stock_location_suppliers")
self.customer_location = self.env.ref("stock.stock_location_customers")
self.stock_location = self.env.ref("stock.stock_location_stock")
self.product_model = self.env["product.product"]
self.lot_model = self.env["stock.lot"]
self.lot_cable = self.env.ref("sale_order_lot_selection.lot_cable")
self.sale = self.env.ref("sale_order_lot_selection.sale1")
super().setUpClass()
cls.prd_cable = cls.env.ref("stock.product_cable_management_box")
cls.prd_cable.tracking = "lot"
cls.product_46 = cls.env.ref("product.product_product_13")
cls.product_12 = cls.env.ref("product.product_product_12")
cls.supplier_location = cls.env.ref("stock.stock_location_suppliers")
cls.customer_location = cls.env.ref("stock.stock_location_customers")
cls.stock_location = cls.env.ref("stock.stock_location_stock")
cls.product_model = cls.env["product.product"]
cls.lot_model = cls.env["stock.lot"]
cls.lot_cable = cls.env.ref("sale_order_lot_selection.lot_cable_demo")
cls.sale = cls.env.ref("sale_order_lot_selection.sale_order_demo")

def _stock_quantity(self, product, lot, location):
def _retrieve_stock_quantity(self, product, lot, location):
return product.with_context(lot_id=lot.id, location=location.id).qty_available

def test_00_stock_available_wrong_lot(self):
# We should not be able to reserve if some stock is available but with another
# lot
self._inventory_products(self.prd_cable, self.lot_cable, 1)
self._update_stock_quantity(self.prd_cable, self.lot_cable, 1)
other_lot = self.env["stock.lot"].create(
{
"name": "test2",
"product_id": self.prd_cable.id,
"company_id": self.env.ref("base.main_company").id,
}
)
self._inventory_products(self.prd_cable, other_lot, 1)
self._update_stock_quantity(self.prd_cable, other_lot, 1)
self.sale.action_confirm()
self.sale.picking_ids.action_assign()
# one of 2 moves should be reserved
Expand All @@ -56,23 +57,17 @@ def test_00_stock_available_wrong_lot(self):
self.assertEqual(len(available_move), 1)
self.assertEqual(len(unavailable_move), 1)

def _inventory_products(self, product, lot, qty):
quant = self.env["stock.quant"].create(
{
"product_id": product.id,
"location_id": self.stock_location.id,
"lot_id": lot.id,
"inventory_quantity": qty,
}
def _update_stock_quantity(self, product, lot, qty):
self.env["stock.quant"]._update_available_quantity(
product, self.stock_location, lot_id=lot, quantity=qty
)
quant.action_apply_inventory()

def test_01_several_lines_with_same_lot(self):
"""You may want split your order in several lines
even if lot/product are the same
use cases: price is different or any shipping information
"""
self._inventory_products(self.prd_cable, self.lot_cable, 10)
self._update_stock_quantity(self.prd_cable, self.lot_cable, 10)
self.sale.action_confirm()

def test_02_sale_order_lot_selection(self):
Expand Down Expand Up @@ -163,55 +158,55 @@ def test_02_sale_order_lot_selection(self):
lot10 = False
lot11 = False
lot12 = False
for ops in picking_in.move_ids_without_package:
if ops.product_id == self.prd_cable:
for move in picking_in.move_ids_without_package:
if move.product_id == self.prd_cable:
lot10 = self.lot_model.create(
{
"name": "0000010",
"product_id": self.prd_cable.id,
"product_qty": ops.product_qty,
"product_qty": move.product_qty,
"company_id": self.env.company.id,
}
)
ops.move_line_ids.write(
{"lot_id": lot10.id, "qty_done": ops.product_qty}
move.move_line_ids.write(
{"lot_id": lot10.id, "quantity": move.product_qty}
)
if ops.product_id == self.product_46:
if move.product_id == self.product_46:
lot11 = self.lot_model.create(
{
"name": "0000011",
"product_id": self.product_46.id,
"product_qty": ops.product_qty,
"product_qty": move.product_qty,
"company_id": self.env.company.id,
}
)
ops.move_line_ids.write(
{"lot_id": lot11.id, "qty_done": ops.product_qty}
move.move_line_ids.write(
{"lot_id": lot11.id, "quantity": move.product_qty}
)
if ops.product_id == self.product_12:
if move.product_id == self.product_12:
lot12 = self.lot_model.create(
{
"name": "0000012",
"product_id": self.product_12.id,
"product_qty": ops.product_qty,
"product_qty": move.product_qty,
"company_id": self.env.company.id,
}
)
ops.move_line_ids.write(
{"lot_id": lot12.id, "qty_done": ops.product_qty}
move.move_line_ids.write(
{"lot_id": lot12.id, "quantity": move.product_qty}
)
picking_in._action_done()
picking_in.button_validate()

# check quantities
lot10_qty_available = self._stock_quantity(
lot10_qty_available = self._retrieve_stock_quantity(
self.prd_cable, lot10, self.stock_location
)
self.assertEqual(lot10_qty_available, 1)
lot11_qty_available = self._stock_quantity(
lot11_qty_available = self._retrieve_stock_quantity(
self.product_46, lot11, self.stock_location
)
self.assertEqual(lot11_qty_available, 2)
lot12_qty_available = self._stock_quantity(
lot12_qty_available = self._retrieve_stock_quantity(
self.product_12, lot12, self.stock_location
)
self.assertEqual(lot12_qty_available, 1)
Expand Down Expand Up @@ -280,15 +275,15 @@ def test_02_sale_order_lot_selection(self):
picking = self.order1.picking_ids

picking_move_line_ids = picking.move_ids_without_package[0].move_line_ids
picking_move_line_ids[0].qty_done = 1
picking_move_line_ids[0].quantity = 1
picking_move_line_ids[0].location_id = self.stock_location
picking.button_validate()

# put back the lot because it is removed by onchange
self.sol3.lot_id = lot10.id
# I'll try to confirm it to check lot reservation:
# lot10 was delivered by order1
lot10_qty_available = self._stock_quantity(
lot10_qty_available = self._retrieve_stock_quantity(
self.prd_cable, lot10, self.stock_location
)
self.order3.action_confirm()
Expand All @@ -302,19 +297,19 @@ def test_02_sale_order_lot_selection(self):
picking = self.order2.picking_ids
picking.action_assign()

picking.move_ids_without_package.mapped("move_line_ids").write({"qty_done": 1})
picking.move_ids_without_package.mapped("move_line_ids").write({"quantity": 1})
picking.button_validate()

# check quantities
lot10_qty_available = self._stock_quantity(
lot10_qty_available = self._retrieve_stock_quantity(
self.prd_cable, lot10, self.stock_location
)
self.assertEqual(lot10_qty_available, 0)
lot11_qty_available = self._stock_quantity(
lot11_qty_available = self._retrieve_stock_quantity(
self.product_46, lot11, self.stock_location
)
self.assertEqual(lot11_qty_available, 1)
lot12_qty_available = self._stock_quantity(
lot12_qty_available = self._retrieve_stock_quantity(
self.product_12, lot12, self.stock_location
)
self.assertEqual(lot12_qty_available, 0)
Expand Down
File renamed without changes.

0 comments on commit 8f1fbb9

Please sign in to comment.