diff options
| author | Nicolas Galler <ngl@odoo.com> | 2020-10-30 11:19:52 +0000 |
|---|---|---|
| committer | Nicolas Galler <ngl@odoo.com> | 2020-10-30 13:54:52 +0000 |
| commit | d013f8641ae2ed8c12d30ba5650c8e6ff2f1d5fd (patch) | |
| tree | 668fe15a08e059444a7372c3ff243dd6e13542fa | |
| parent | 112cf9088190606b85f60b420d50fbd1100e1f38 (diff) | |
[FIX] stock: consistently use translated value for product description
Behavior prior to this commit:
In a multi-lingual setup, when entering a SO for a customer set in
a non-default language with a product that has translation in both
languages and is set up to replenish on order, the description in the
generated RFQ is duplicated, for example: "Product test Test Product in Dutch"
The problem stems from the fact that the description on the generated
stock move is set to the translated name of the product. When
generating the PO, the stock move class removes the product name to
avoid duplicating the description, but it uses the non-translated name
in the comparison.
Behavior after this commit:
The description on the RFQ line is included only once (using the default
language for the database)
opw-2368562
closes odoo/odoo#61040
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
| -rw-r--r-- | addons/purchase_stock/tests/test_reordering_rule.py | 84 | ||||
| -rw-r--r-- | addons/stock/models/stock_move.py | 11 | ||||
| -rw-r--r-- | addons/stock/models/stock_picking.py | 2 |
3 files changed, 93 insertions, 4 deletions
diff --git a/addons/purchase_stock/tests/test_reordering_rule.py b/addons/purchase_stock/tests/test_reordering_rule.py index ddd2f9258a8..dd1176e5016 100644 --- a/addons/purchase_stock/tests/test_reordering_rule.py +++ b/addons/purchase_stock/tests/test_reordering_rule.py @@ -432,3 +432,87 @@ class TestReorderingRule(SavepointCase): [("product_id", "=", product.id)]) self.assertTrue(po_line) self.assertEqual(po_line.partner_id, secondary_vendor) + + def test_procure_multi_lingual(self): + """ + Define a product with description in English and French. + Run a procurement specifying a group_id with a partner (customer) + set up with French as language. Verify that the PO is generated + using the default (English) language. + """ + purchase_route = self.env.ref("purchase_stock.route_warehouse0_buy") + # create a new warehouse to make sure it gets the mts/mto rule + warehouse = self.env['stock.warehouse'].create({ + "name": "test warehouse", + "active": True, + 'reception_steps': 'one_step', + 'delivery_steps': 'ship_only', + 'code': 'TEST' + }) + customer_loc, _ = warehouse._get_partner_locations() + mto_rule = self.env['stock.rule'].search( + [('warehouse_id', '=', warehouse.id), + ('procure_method', '=', 'mts_else_mto'), + ('location_id', '=', customer_loc.id) + ] + ) + route_mto = self.env["stock.location.route"].create({ + "name": "MTO", + "active": True, + "sequence": 3, + "product_selectable": True, + "rule_ids": [(6, 0, [ + mto_rule.id + ])] + }) + uom_unit = self.env.ref("uom.product_uom_unit") + product = self.env["product.product"].create({ + "name": "product TEST", + "standard_price": 100.0, + "type": "product", + "uom_id": uom_unit.id, + "default_code": "A", + "route_ids": [(6, 0, [ + route_mto.id, + purchase_route.id, + ])], + }) + self.env['res.lang']._activate_lang('fr_FR') + self.env['ir.translation']._set_ids('product.template,name', 'model', 'fr_FR', product.product_tmpl_id.ids, 'produit en français') + self.env['ir.translation']._set_ids('product.product,name', 'model', 'fr_FR', product.ids, 'produit en français') + default_vendor = self.env["res.partner"].create({ + "name": "Supplier A", + }) + self.env["product.supplierinfo"].create({ + "name": default_vendor.id, + "product_tmpl_id": product.product_tmpl_id.id, + "delay": 7, + }) + customer = self.env["res.partner"].create({ + "name": "Customer", + "lang": "fr_FR" + }) + proc_group = self.env["procurement.group"].create({ + "partner_id": customer.id + }) + procurement = self.env["procurement.group"].Procurement( + product, 100, uom_unit, + customer.property_stock_customer, + "Test default vendor", + "/", + self.env.company, + { + "warehouse_id": warehouse, + "date_planned": dt.today() + td(days=15), + "group_id": proc_group, + "route_ids": [], + } + ) + self.env.cache.invalidate() + + self.env["procurement.group"].run([procurement]) + + po_line = self.env["purchase.order.line"].search( + [("product_id", "=", product.id)]) + self.assertTrue(po_line) + self.assertEqual("product TEST", po_line.name) diff --git a/addons/stock/models/stock_move.py b/addons/stock/models/stock_move.py index 7bf5238cbb3..98ed757687f 100644 --- a/addons/stock/models/stock_move.py +++ b/addons/stock/models/stock_move.py @@ -183,7 +183,7 @@ class StockMove(models.Model): @api.onchange('product_id', 'picking_type_id') def onchange_product(self): if self.product_id: - product = self.product_id.with_context(lang=self.picking_id.partner_id.lang or self.env.user.lang) + product = self.product_id.with_context(lang=self._get_lang()) self.description_picking = product._get_description(self.picking_type_id) @api.depends('has_tracking', 'picking_type_id.use_create_lots', 'picking_type_id.use_existing_lots', 'state') @@ -858,7 +858,7 @@ class StockMove(models.Model): @api.onchange('product_id') def onchange_product_id(self): - product = self.product_id.with_context(lang=self.partner_id.lang or self.env.user.lang) + product = self.product_id.with_context(lang=self._get_lang()) self.name = product.partner_ref self.product_uom = product.uom_id.id @@ -1135,8 +1135,9 @@ class StockMove(models.Model): group_id = self.rule_id.group_id elif self.rule_id.group_propagation_option == 'none': group_id = False + product_id = self.product_id.with_context(lang=self._get_lang()) return { - 'product_description_variants': self.description_picking and self.description_picking.replace(self.product_id._get_description(self.picking_type_id), ''), + 'product_description_variants': self.description_picking and self.description_picking.replace(product_id._get_description(self.picking_type_id), ''), 'date_planned': self.date, 'date_deadline': self.date_deadline, 'move_dest_ids': self, @@ -1604,6 +1605,10 @@ class StockMove(models.Model): def _consuming_picking_types(self): return ['outgoing'] + def _get_lang(self): + """Determine language to use for translated description""" + return self.picking_id.partner_id.lang or self.partner_id.lang or self.env.user.lang + def _get_source_document(self): """ Return the move's document, used by `report.stock.report_product_product_replenishment` and must be overrided to add more document type in the report. diff --git a/addons/stock/models/stock_picking.py b/addons/stock/models/stock_picking.py index e568579f203..6b8e965eb8d 100644 --- a/addons/stock/models/stock_picking.py +++ b/addons/stock/models/stock_picking.py @@ -649,7 +649,7 @@ class Picking(models.Model): if vals.get('picking_type_id'): for move in res.move_lines: if not move.description_picking: - move.description_picking = move.product_id._get_description(move.picking_id.picking_type_id) + move.description_picking = move.product_id.with_context(lang=move._get_lang())._get_description(move.picking_id.picking_type_id) return res |
