From 699a4614effbc35b527185fe8ad7cdb6e5b52c12 Mon Sep 17 00:00:00 2001 From: Victor Feyens Date: Wed, 14 Aug 2019 10:23:38 +0000 Subject: [PATCH] [FIX] purchase(_product_matrix): no_variant attributes Display no variant infos in the purchase order line description. closes odoo/odoo#35717 Signed-off-by: Damien Bouvy (dbo) --- addons/purchase/models/purchase.py | 12 +++++++++--- addons/purchase_product_matrix/models/purchase.py | 12 ++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/addons/purchase/models/purchase.py b/addons/purchase/models/purchase.py index 72bfab95f50..816f093eaff 100644 --- a/addons/purchase/models/purchase.py +++ b/addons/purchase/models/purchase.py @@ -614,9 +614,7 @@ class PurchaseOrderLine(models.Model): partner_id=self.partner_id.id, company_id=self.company_id.id, ) - self.name = product_lang.display_name - if product_lang.description_purchase: - self.name += '\n' + product_lang.description_purchase + self.name = self._get_product_purchase_description(product_lang) self._compute_tax_id() @@ -693,6 +691,14 @@ class PurchaseOrderLine(models.Model): else: self.product_qty = 1.0 + def _get_product_purchase_description(self, product_lang): + self.ensure_one() + name = product_lang.display_name + if product_lang.description_purchase: + name += '\n' + product_lang.description_purchase + + return name + def _prepare_account_move_line(self, move): self.ensure_one() if self.product_id.purchase_method == 'purchase': diff --git a/addons/purchase_product_matrix/models/purchase.py b/addons/purchase_product_matrix/models/purchase.py index a319bbdd9cb..ffdab9596b7 100644 --- a/addons/purchase_product_matrix/models/purchase.py +++ b/addons/purchase_product_matrix/models/purchase.py @@ -88,14 +88,11 @@ class PurchaseOrder(models.Model): if not default_po_line_vals: OrderLine = self.env['purchase.order.line'] default_po_line_vals = OrderLine.default_get(OrderLine._fields.keys()) - pnvav = [] # product no variant attribute values - for nvav in no_variant_attribute_values: - pnvav.append((4, nvav)) new_lines.append((0, 0, dict( default_po_line_vals, product_id=product.id, product_qty=qty, - product_no_variant_attribute_value_ids=pnvav) + product_no_variant_attribute_value_ids=no_variant_attribute_values.ids) )) if new_lines: self.update(dict(order_line=new_lines)) @@ -146,3 +143,10 @@ class PurchaseOrderLine(models.Model): is_configurable_product = fields.Boolean('Is the product configurable?', related="product_template_id.has_configurable_attributes") product_template_attribute_value_ids = fields.Many2many(related='product_id.product_template_attribute_value_ids', readonly=True) product_no_variant_attribute_value_ids = fields.Many2many('product.template.attribute.value', string='Product attribute values that do not create variants') + + def _get_product_purchase_description(self, product): + name = super(PurchaseOrderLine, self)._get_product_purchase_description(product) + for no_variant_attribute_value in self.product_no_variant_attribute_value_ids: + name += "\n" + no_variant_attribute_value.attribute_id.name + ': ' + no_variant_attribute_value.name + + return name