Skip to content

Commit aa5228d

Browse files
committed
Merge pull request #1 from Groupe-Voltaire-SAS/16.0-imp-purchase_lot-update-restrict-lot_pol
16.0 imp purchase lot update restrict lot on purchase order line
2 parents 2c0d84a + f332134 commit aa5228d

File tree

3 files changed

+80
-7
lines changed

3 files changed

+80
-7
lines changed

purchase_lot/models/purchase_order_line.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,17 @@ class PurchaseOrderLine(models.Model):
1717
store=True,
1818
)
1919

20-
@api.depends("move_dest_ids.restrict_lot_id", "move_ids.restrict_lot_id")
20+
@api.depends(
21+
"move_dest_ids.restrict_lot_id",
22+
"move_ids.restrict_lot_id",
23+
"sale_line_id.lot_id",
24+
)
2125
def _compute_lot_id(self):
2226
for line in self:
2327
line.lot_id = (
24-
line.move_dest_ids.restrict_lot_id | line.move_ids.restrict_lot_id
28+
line.move_dest_ids.restrict_lot_id
29+
| line.move_ids.restrict_lot_id
30+
| line.sale_line_id.lot_id
2531
)
2632

2733
@api.model

purchase_lot/static/description/index.html

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
<?xml version="1.0" encoding="utf-8"?>
21
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
32
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
43
<head>
@@ -9,10 +8,11 @@
98

109
/*
1110
:Author: David Goodger ([email protected])
12-
:Id: $Id: html4css1.css 8954 2022-01-20 10:10:25Z milde $
11+
:Id: $Id: html4css1.css 9511 2024-01-13 09:50:07Z milde $
1312
:Copyright: This stylesheet has been placed in the public domain.
1413
1514
Default cascading style sheet for the HTML output of Docutils.
15+
Despite the name, some widely supported CSS2 features are used.
1616
1717
See https://docutils.sourceforge.io/docs/howto/html-stylesheets.html for how to
1818
customize this style sheet.
@@ -275,7 +275,7 @@
275275
margin-left: 2em ;
276276
margin-right: 2em }
277277

278-
pre.code .ln { color: grey; } /* line numbers */
278+
pre.code .ln { color: gray; } /* line numbers */
279279
pre.code, code { background-color: #eeeeee }
280280
pre.code .comment, code .comment { color: #5C6576 }
281281
pre.code .keyword, code .keyword { color: #3B0D06; font-weight: bold }
@@ -301,7 +301,7 @@
301301
span.pre {
302302
white-space: pre }
303303

304-
span.problematic {
304+
span.problematic, pre.problematic {
305305
color: red }
306306

307307
span.section-subtitle {
@@ -410,7 +410,9 @@ <h2><a class="toc-backref" href="#toc-entry-4">Contributors</a></h2>
410410
<div class="section" id="maintainers">
411411
<h2><a class="toc-backref" href="#toc-entry-5">Maintainers</a></h2>
412412
<p>This module is maintained by the OCA.</p>
413-
<a class="reference external image-reference" href="https://odoo-community.org"><img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /></a>
413+
<a class="reference external image-reference" href="https://odoo-community.org">
414+
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />
415+
</a>
414416
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
415417
mission is to support the collaborative development of Odoo features and
416418
promote its widespread use.</p>

purchase_lot/tests/test_purchase_lot.py

+65
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Copyright (C) 2022 Akretion (<http://www.akretion.com>).
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

4+
from odoo.tests import Form
45
from odoo.tests.common import TransactionCase
6+
from odoo.tools import mute_logger
57

68

79
class TestPurchaseLot(TransactionCase):
@@ -31,6 +33,24 @@ def setUpClass(cls):
3133
}
3234
)
3335
cls.out_picking_type = cls.env.ref("stock.picking_type_out")
36+
cls.supplier = cls.env["res.partner"].create({"name": "Vendor"})
37+
cls.customer = cls.env["res.partner"].create({"name": "Customer"})
38+
cls.external_serial_product = cls.env["product.product"].create(
39+
{
40+
"name": "Pen drive",
41+
"type": "product",
42+
"categ_id": cls.env.ref("product.product_category_1").id,
43+
"lst_price": 100.0,
44+
"standard_price": 0.0,
45+
"uom_id": cls.env.ref("uom.product_uom_unit").id,
46+
"uom_po_id": cls.env.ref("uom.product_uom_unit").id,
47+
"seller_ids": [
48+
(0, 0, {"delay": 1, "partner_id": cls.supplier.id, "min_qty": 2.0})
49+
],
50+
"route_ids": [(4, buy_route.id, 0), (4, mto_route.id, 0)],
51+
}
52+
)
53+
cls.external_serial_product.product_tmpl_id.tracking = "serial"
3454

3555
def test_purchase_lot(self):
3656
lot1 = self.env["stock.lot"].create(
@@ -88,3 +108,48 @@ def test_purchase_lot(self):
88108
self.assertEqual(pol1.lot_id.id, lot1.id)
89109
pol1.order_id.button_confirm()
90110
self.assertEqual(pol1.move_ids.restrict_lot_id.id, lot1.id)
111+
112+
def test_lot_propagation(self):
113+
# Required for `route_id` to be visible in the view
114+
self.env.user.groups_id += self.env.ref("stock.group_adv_location")
115+
116+
# Create a sales order with a line of 200 PCE incoming shipment,
117+
# with route_id drop shipping
118+
so_form = Form(self.env["sale.order"])
119+
so_form.partner_id = self.customer
120+
so_form.payment_term_id = self.env.ref(
121+
"account.account_payment_term_end_following_month"
122+
)
123+
with mute_logger("odoo.tests.common.onchange"):
124+
# otherwise complains that there's not enough inventory and
125+
# apparently that's normal according to @jco and @sle
126+
with so_form.order_line.new() as line:
127+
line.product_id = self.external_serial_product
128+
line.product_uom_qty = 200
129+
line.price_unit = 1.00
130+
line.route_id = self.env.ref("purchase_stock.route_warehouse0_buy")
131+
132+
sale_order_drp_shpng = so_form.save()
133+
sale_order_drp_shpng.order_line.lot_id = self.env["stock.lot"].create(
134+
{
135+
"name": "Seq test DS pdt",
136+
"product_id": self.external_serial_product.id,
137+
}
138+
)
139+
initial_lot = sale_order_drp_shpng.order_line.lot_id
140+
# Confirm sales order
141+
sale_order_drp_shpng.action_confirm()
142+
143+
# Check a quotation was created to a certain vendor
144+
# and confirm so it becomes a confirmed purchase order
145+
purchase = self.env["purchase.order"].search(
146+
[("partner_id", "=", self.supplier.id)]
147+
)
148+
self.assertEqual(purchase.state, "draft")
149+
self.assertTrue(purchase.order_line.lot_id)
150+
self.assertEqual(purchase.order_line.lot_id, initial_lot)
151+
purchase.button_confirm()
152+
purchase.button_approve()
153+
self.assertTrue(purchase.picking_ids.move_ids.restrict_lot_id)
154+
self.assertTrue(purchase.order_line.lot_id)
155+
self.assertEqual(purchase.order_line.lot_id, initial_lot)

0 commit comments

Comments
 (0)