From e7f18f7d86c128df4b5a9389b28a7c94ea034a7b Mon Sep 17 00:00:00 2001 From: Alfredo Date: Thu, 5 Dec 2024 12:49:39 +0100 Subject: [PATCH] [14.0][IMP] product_pricelist_last_purchase_price: If find more than one product supplierinfo, take the one with the lowest sequence. --- product_pricelist_last_purchase_price/i18n/en_GB.po | 10 ++++++++++ product_pricelist_last_purchase_price/i18n/es.po | 12 ++++++++++++ .../i18n/product_pricelist_last_purchase_price.pot | 10 ++++++++++ .../models/account_move.py | 10 ++++++++-- .../models/purchase_order.py | 9 ++++++++- 5 files changed, 48 insertions(+), 3 deletions(-) diff --git a/product_pricelist_last_purchase_price/i18n/en_GB.po b/product_pricelist_last_purchase_price/i18n/en_GB.po index 25818cc3e2..fddab32bda 100644 --- a/product_pricelist_last_purchase_price/i18n/en_GB.po +++ b/product_pricelist_last_purchase_price/i18n/en_GB.po @@ -84,3 +84,13 @@ msgstr "" #: model_terms:ir.ui.view,arch_db:product_pricelist_last_purchase_price.view_res_partner_filter msgid "Update Price From Order" msgstr "" + +#. module: product_pricelist_last_purchase_price +#: code:addons/product_pricelist_last_purchase_price/models/account_move.py:0 +#: code:addons/product_pricelist_last_purchase_price/models/purchase_order.py:0 +#, python-format +msgid "" +"The product: %(product)s has been repeated more than once by supplier: " +"%(supplier)s." +msgstr "" + diff --git a/product_pricelist_last_purchase_price/i18n/es.po b/product_pricelist_last_purchase_price/i18n/es.po index a9bfec9e9e..17cbe98cf1 100644 --- a/product_pricelist_last_purchase_price/i18n/es.po +++ b/product_pricelist_last_purchase_price/i18n/es.po @@ -84,3 +84,15 @@ msgstr "Actualizar precio desde factura" #: model_terms:ir.ui.view,arch_db:product_pricelist_last_purchase_price.view_res_partner_filter msgid "Update Price From Order" msgstr "Actualizar precio desde pedido" + +#. module: product_pricelist_last_purchase_price +#: code:addons/product_pricelist_last_purchase_price/models/account_move.py:0 +#: code:addons/product_pricelist_last_purchase_price/models/purchase_order.py:0 +#, python-format +msgid "" +"The product: %(product)s has been repeated more than once by supplier: " +"%(supplier)s." +msgstr "" +"El producto: %(product)s tiene repetido mas de una vez al proveedor: " +"%(supplier)s." + diff --git a/product_pricelist_last_purchase_price/i18n/product_pricelist_last_purchase_price.pot b/product_pricelist_last_purchase_price/i18n/product_pricelist_last_purchase_price.pot index 25818cc3e2..fddab32bda 100644 --- a/product_pricelist_last_purchase_price/i18n/product_pricelist_last_purchase_price.pot +++ b/product_pricelist_last_purchase_price/i18n/product_pricelist_last_purchase_price.pot @@ -84,3 +84,13 @@ msgstr "" #: model_terms:ir.ui.view,arch_db:product_pricelist_last_purchase_price.view_res_partner_filter msgid "Update Price From Order" msgstr "" + +#. module: product_pricelist_last_purchase_price +#: code:addons/product_pricelist_last_purchase_price/models/account_move.py:0 +#: code:addons/product_pricelist_last_purchase_price/models/purchase_order.py:0 +#, python-format +msgid "" +"The product: %(product)s has been repeated more than once by supplier: " +"%(supplier)s." +msgstr "" + diff --git a/product_pricelist_last_purchase_price/models/account_move.py b/product_pricelist_last_purchase_price/models/account_move.py index 6302172e02..8eb12a6041 100644 --- a/product_pricelist_last_purchase_price/models/account_move.py +++ b/product_pricelist_last_purchase_price/models/account_move.py @@ -1,7 +1,7 @@ # Copyright 2024 Alfredo de la Fuente - AvanzOSC # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from odoo import fields, models -from odoo.exceptions import AccessError +from odoo import _, fields, models +from odoo.exceptions import AccessError, ValidationError class AccountMove(models.Model): @@ -93,6 +93,12 @@ def _find_seller_to_update_suppliernfo_to_product(self, line, partner): lambda x: x.name == partner and (x.price != line.price_unit or x.discount != line.discount) ) + if len(seller) > 1: + message = _( + "The product: %(product)s has been repeated more than " + "once by supplier: %(supplier)s." + ) % {"product": line.product_id.name, "supplier": partner.name} + raise ValidationError(message) if seller and seller.not_update_price_from_invoice: seller = False return seller diff --git a/product_pricelist_last_purchase_price/models/purchase_order.py b/product_pricelist_last_purchase_price/models/purchase_order.py index 19a95036cf..3b1cf87f8c 100644 --- a/product_pricelist_last_purchase_price/models/purchase_order.py +++ b/product_pricelist_last_purchase_price/models/purchase_order.py @@ -1,6 +1,7 @@ # Copyright 2024 Alfredo de la Fuente - AvanzOSC # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). -from odoo import models +from odoo import _, models +from odoo.exceptions import ValidationError class PurchaseOrder(models.Model): @@ -10,6 +11,12 @@ def _find_seller_to_update_suppliernfo_to_product(self, line, partner): seller = super( PurchaseOrder, self )._find_seller_to_update_suppliernfo_to_product(line, partner) + if len(seller) > 1: + message = _( + "The product: %(product)s has been repeated more than " + "once by supplier: %(supplier)s." + ) % {"product": line.product_id.name, "supplier": partner.name} + raise ValidationError(message) if seller and seller.not_update_price_from_order: seller = False return seller