|
1 | 1 | # Copyright (C) 2022 Akretion (<http://www.akretion.com>).
|
2 | 2 | # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
3 | 3 |
|
| 4 | +from odoo.tests import Form |
4 | 5 | from odoo.tests.common import TransactionCase
|
| 6 | +from odoo.tools import mute_logger |
5 | 7 |
|
6 | 8 |
|
7 | 9 | class TestPurchaseLot(TransactionCase):
|
@@ -31,6 +33,24 @@ def setUpClass(cls):
|
31 | 33 | }
|
32 | 34 | )
|
33 | 35 | 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" |
34 | 54 |
|
35 | 55 | def test_purchase_lot(self):
|
36 | 56 | lot1 = self.env["stock.lot"].create(
|
@@ -88,3 +108,48 @@ def test_purchase_lot(self):
|
88 | 108 | self.assertEqual(pol1.lot_id.id, lot1.id)
|
89 | 109 | pol1.order_id.button_confirm()
|
90 | 110 | 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