|
| 1 | +# Copyright 2021 Camptocamp SA |
| 2 | +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html) |
| 3 | + |
| 4 | +from odoo import fields |
| 5 | +from odoo.tests.common import SavepointCase |
| 6 | + |
| 7 | + |
| 8 | +class TestPurchaseOrderDescription(SavepointCase): |
| 9 | + @classmethod |
| 10 | + def setUpClass(cls): |
| 11 | + super().setUpClass() |
| 12 | + cls.partner_1 = cls.env.ref("base.res_partner_1") |
| 13 | + cls.product_with_acc_desc = cls.env.ref("product.product_product_1") |
| 14 | + cls.product_without_acc_desc = cls.env.ref("product.product_product_2") |
| 15 | + |
| 16 | + consumable_cat = cls.env["product.category"].search( |
| 17 | + [("name", "=", "Consumable")] |
| 18 | + ) |
| 19 | + |
| 20 | + cls.product_with_acc_desc.categ_id = consumable_cat |
| 21 | + cls.product_without_acc_desc.categ_id = consumable_cat |
| 22 | + |
| 23 | + cls.product_with_acc_desc.purchase_method = "purchase" |
| 24 | + cls.product_without_acc_desc.purchase_method = "purchase" |
| 25 | + |
| 26 | + cls.product_with_acc_desc.accounting_description = "Product1_acc_desc" |
| 27 | + |
| 28 | + cls.po_product_with_acc = cls.env["purchase.order"].create( |
| 29 | + { |
| 30 | + "partner_id": cls.partner_1.id, |
| 31 | + "order_line": [ |
| 32 | + ( |
| 33 | + 0, |
| 34 | + 0, |
| 35 | + { |
| 36 | + "product_id": cls.product_with_acc_desc.id, |
| 37 | + "product_qty": 5.0, |
| 38 | + "product_uom": cls.product_with_acc_desc.uom_id.id, |
| 39 | + "price_unit": 10, |
| 40 | + "date_planned": fields.Datetime.now(), |
| 41 | + }, |
| 42 | + ) |
| 43 | + ], |
| 44 | + } |
| 45 | + ) |
| 46 | + cls.po_product_with_acc_line = cls.po_product_with_acc.order_line |
| 47 | + cls.po_product_with_acc.button_confirm() |
| 48 | + cls.po_product_with_acc.button_approve() |
| 49 | + |
| 50 | + cls.po_product_without_acc = cls.env["purchase.order"].create( |
| 51 | + { |
| 52 | + "partner_id": cls.partner_1.id, |
| 53 | + "order_line": [ |
| 54 | + ( |
| 55 | + 0, |
| 56 | + 0, |
| 57 | + { |
| 58 | + "product_id": cls.product_without_acc_desc.id, |
| 59 | + "product_qty": 5.0, |
| 60 | + "product_uom": cls.product_without_acc_desc.uom_id.id, |
| 61 | + "price_unit": 10, |
| 62 | + "date_planned": fields.Datetime.now(), |
| 63 | + }, |
| 64 | + ) |
| 65 | + ], |
| 66 | + } |
| 67 | + ) |
| 68 | + cls.po_product_without_acc_line = cls.po_product_without_acc.order_line |
| 69 | + cls.po_product_without_acc.button_confirm() |
| 70 | + cls.po_product_without_acc.button_approve() |
| 71 | + |
| 72 | + def test_purchase_order_line_name(self): |
| 73 | + |
| 74 | + # For 1st PO check invoice line is same as product description |
| 75 | + action_1 = self.po_product_with_acc.action_create_invoice() |
| 76 | + inv_1 = self.env["account.move"].browse(action_1["res_id"]) |
| 77 | + inv_line_with_product = inv_1.line_ids.filtered(lambda x: x.product_id) |
| 78 | + |
| 79 | + self.assertTrue(self.product_with_acc_desc.accounting_description) |
| 80 | + self.assertEqual( |
| 81 | + inv_line_with_product.name, |
| 82 | + self.product_with_acc_desc.accounting_description, |
| 83 | + ) |
| 84 | + self.assertIn( |
| 85 | + inv_line_with_product.product_id.name, inv_line_with_product.external_name |
| 86 | + ) |
| 87 | + |
| 88 | + # For 2nd PO make sure invoice line name isn't set to product description |
| 89 | + action_2 = self.po_product_without_acc.action_create_invoice() |
| 90 | + inv_2 = self.env["account.move"].browse(action_2["res_id"]) |
| 91 | + inv_line_with_product = inv_2.line_ids.filtered(lambda x: x.product_id) |
| 92 | + |
| 93 | + self.assertFalse(self.product_without_acc_desc.accounting_description) |
| 94 | + self.assertNotEqual( |
| 95 | + inv_line_with_product.name, |
| 96 | + self.product_without_acc_desc.accounting_description, |
| 97 | + ) |
| 98 | + self.assertIn( |
| 99 | + inv_line_with_product.product_id.name, inv_line_with_product.external_name |
| 100 | + ) |
0 commit comments