From 3d3e61ddfe20e670b9b59a4c4712cc3070e9fe9a Mon Sep 17 00:00:00 2001 From: Alfredo Date: Wed, 25 Sep 2024 13:42:22 +0200 Subject: [PATCH] [14.0][ADD] purchase_update_pricelist: When confirming a purchase order, update the price unit and discount in "Supplier Pricelist". --- purchase_update_pricelist/README.rst | 30 ++++++++++++++ purchase_update_pricelist/__init__.py | 1 + purchase_update_pricelist/__manifest__.py | 14 +++++++ purchase_update_pricelist/i18n/en_GB.po | 36 +++++++++++++++++ purchase_update_pricelist/i18n/es.po | 36 +++++++++++++++++ .../i18n/purchase_update_pricelist.pot | 36 +++++++++++++++++ purchase_update_pricelist/models/__init__.py | 1 + .../models/purchase_order.py | 39 +++++++++++++++++++ .../odoo/addons/purchase_update_pricelist | 1 + setup/purchase_update_pricelist/setup.py | 6 +++ 10 files changed, 200 insertions(+) create mode 100644 purchase_update_pricelist/README.rst create mode 100644 purchase_update_pricelist/__init__.py create mode 100644 purchase_update_pricelist/__manifest__.py create mode 100644 purchase_update_pricelist/i18n/en_GB.po create mode 100644 purchase_update_pricelist/i18n/es.po create mode 100644 purchase_update_pricelist/i18n/purchase_update_pricelist.pot create mode 100644 purchase_update_pricelist/models/__init__.py create mode 100644 purchase_update_pricelist/models/purchase_order.py create mode 120000 setup/purchase_update_pricelist/odoo/addons/purchase_update_pricelist create mode 100644 setup/purchase_update_pricelist/setup.py diff --git a/purchase_update_pricelist/README.rst b/purchase_update_pricelist/README.rst new file mode 100644 index 0000000000..d42c47656f --- /dev/null +++ b/purchase_update_pricelist/README.rst @@ -0,0 +1,30 @@ +.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 + +========================= +Purchase update pricelist +========================= + +* When confirming a purchase order, update the price unit and discount in + "Supplier Pricelist". + + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues +`_. In case of trouble, +please check there if your issue has already been reported. If you spotted +it first, help us smash it by providing detailed and welcomed feedback. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Contributors +------------ + +* Ana Juaristi +* Alfredo de la Fuente diff --git a/purchase_update_pricelist/__init__.py b/purchase_update_pricelist/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/purchase_update_pricelist/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/purchase_update_pricelist/__manifest__.py b/purchase_update_pricelist/__manifest__.py new file mode 100644 index 0000000000..32cfd00387 --- /dev/null +++ b/purchase_update_pricelist/__manifest__.py @@ -0,0 +1,14 @@ +# Copyright 2024 Alfredo de la Fuente - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +{ + "name": "Purchase Update Pricelist", + "version": "14.0.1.0.0", + "category": "Inventory/Purchase", + "license": "AGPL-3", + "author": "AvanzOSC", + "website": "https://github.com/avanzosc/odoo-addons", + "depends": ["purchase", "purchase_discount"], + "excludes": [], + "data": [], + "installable": True, +} diff --git a/purchase_update_pricelist/i18n/en_GB.po b/purchase_update_pricelist/i18n/en_GB.po new file mode 100644 index 0000000000..84a3538641 --- /dev/null +++ b/purchase_update_pricelist/i18n/en_GB.po @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_update_pricelist +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-09-25 11:36+0000\n" +"PO-Revision-Date: 2024-09-25 11:36+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: purchase_update_pricelist +#: model:ir.model.fields,field_description:purchase_update_pricelist.field_purchase_order__display_name +msgid "Display Name" +msgstr "" + +#. module: purchase_update_pricelist +#: model:ir.model.fields,field_description:purchase_update_pricelist.field_purchase_order__id +msgid "ID" +msgstr "" + +#. module: purchase_update_pricelist +#: model:ir.model.fields,field_description:purchase_update_pricelist.field_purchase_order____last_update +msgid "Last Modified on" +msgstr "" + +#. module: purchase_update_pricelist +#: model:ir.model,name:purchase_update_pricelist.model_purchase_order +msgid "Purchase Order" +msgstr "" diff --git a/purchase_update_pricelist/i18n/es.po b/purchase_update_pricelist/i18n/es.po new file mode 100644 index 0000000000..620ee263a2 --- /dev/null +++ b/purchase_update_pricelist/i18n/es.po @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_update_pricelist +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-09-25 11:32+0000\n" +"PO-Revision-Date: 2024-09-25 11:32+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: purchase_update_pricelist +#: model:ir.model.fields,field_description:purchase_update_pricelist.field_purchase_order__display_name +msgid "Display Name" +msgstr "Nombre mostrado" + +#. module: purchase_update_pricelist +#: model:ir.model.fields,field_description:purchase_update_pricelist.field_purchase_order__id +msgid "ID" +msgstr "ID" + +#. module: purchase_update_pricelist +#: model:ir.model.fields,field_description:purchase_update_pricelist.field_purchase_order____last_update +msgid "Last Modified on" +msgstr "Última modificación el" + +#. module: purchase_update_pricelist +#: model:ir.model,name:purchase_update_pricelist.model_purchase_order +msgid "Purchase Order" +msgstr "Pedido de compra" diff --git a/purchase_update_pricelist/i18n/purchase_update_pricelist.pot b/purchase_update_pricelist/i18n/purchase_update_pricelist.pot new file mode 100644 index 0000000000..8bc2ef8630 --- /dev/null +++ b/purchase_update_pricelist/i18n/purchase_update_pricelist.pot @@ -0,0 +1,36 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_update_pricelist +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-09-25 11:32+0000\n" +"PO-Revision-Date: 2024-09-25 11:32+0000\n" +"Last-Translator: \n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: purchase_update_pricelist +#: model:ir.model.fields,field_description:purchase_update_pricelist.field_purchase_order__display_name +msgid "Display Name" +msgstr "" + +#. module: purchase_update_pricelist +#: model:ir.model.fields,field_description:purchase_update_pricelist.field_purchase_order__id +msgid "ID" +msgstr "" + +#. module: purchase_update_pricelist +#: model:ir.model.fields,field_description:purchase_update_pricelist.field_purchase_order____last_update +msgid "Last Modified on" +msgstr "" + +#. module: purchase_update_pricelist +#: model:ir.model,name:purchase_update_pricelist.model_purchase_order +msgid "Purchase Order" +msgstr "" diff --git a/purchase_update_pricelist/models/__init__.py b/purchase_update_pricelist/models/__init__.py new file mode 100644 index 0000000000..9f03530643 --- /dev/null +++ b/purchase_update_pricelist/models/__init__.py @@ -0,0 +1 @@ +from . import purchase_order diff --git a/purchase_update_pricelist/models/purchase_order.py b/purchase_update_pricelist/models/purchase_order.py new file mode 100644 index 0000000000..f42e402699 --- /dev/null +++ b/purchase_update_pricelist/models/purchase_order.py @@ -0,0 +1,39 @@ +# Copyright 2024 Alfredo de la Fuente - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import models + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + def _add_supplier_to_product(self): + result = super(PurchaseOrder, self)._add_supplier_to_product() + self._update_supplier_info_to_product() + return result + + def _update_supplier_info_to_product(self): + for line in self.order_line: + partner = ( + self.partner_id + if not self.partner_id.parent_id + else self.partner_id.parent_id + ) + seller = self._find_seller_to_update_suppliernfo_to_product(line, partner) + if seller: + vals = self._catch_values_to_update_seller_in_product(line, seller) + seller.write(vals) + + def _catch_values_to_update_seller_in_product(self, line, seller): + vals = {} + if seller.price != line.price_unit: + vals["price"] = line.price_unit + if seller.discount != line.discount: + vals["discount"] = line.discount + return vals + + def _find_seller_to_update_suppliernfo_to_product(self, line, partner): + seller = line.product_id.seller_ids.filtered( + lambda x: x.name == partner + and (x.price != line.price_unit or x.discount != line.discount) + ) + return seller diff --git a/setup/purchase_update_pricelist/odoo/addons/purchase_update_pricelist b/setup/purchase_update_pricelist/odoo/addons/purchase_update_pricelist new file mode 120000 index 0000000000..9b412f954a --- /dev/null +++ b/setup/purchase_update_pricelist/odoo/addons/purchase_update_pricelist @@ -0,0 +1 @@ +../../../../purchase_update_pricelist \ No newline at end of file diff --git a/setup/purchase_update_pricelist/setup.py b/setup/purchase_update_pricelist/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/purchase_update_pricelist/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)