diff --git a/purchase_order_general_discount/README.rst b/purchase_order_general_discount/README.rst new file mode 100644 index 00000000000..33041af373e --- /dev/null +++ b/purchase_order_general_discount/README.rst @@ -0,0 +1,136 @@ +=============================== +Purchase Order General Discount +=============================== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:58805054abf039c59925ef0f83b9d3521ed2a043b376d7411ab967d36068ede5 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpurchase--workflow-lightgray.png?logo=github + :target: https://github.com/OCA/purchase-workflow/tree/18.0/purchase_order_general_discount + :alt: OCA/purchase-workflow +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/purchase-workflow-18-0/purchase-workflow-18-0-purchase_order_general_discount + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/purchase-workflow&target_branch=18.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +This module allows to set a general discount in a purchase order. This +general discount is applied to each line order. + +You can also set a default general discount on suppliers and configure +to which line field the discount will be applied. + +**Table of contents** + +.. contents:: + :local: + +Configuration +============= + +You can set in settings another discount field to be applied. For +example, if we had purchase_triple_discount, we could set the general +discount in discount3 to be applied after all other discounts. + +To do so: + +1. Go to *Purchases > Configuration > Settings* and *Purchase Discount + Field* +2. Select the discount you'd wish to use. purchase_triple_discount + fields will appear when the module is installed. + +There's a method at res.company called \_get_purchase_discount_fields +that can be used to extend more line discount fields. For example, if we +had the field discount4, we could extend it like this: + +.. code:: python + + @api.model + def _get_purchase_discount_fields(self): + discount_fields = super()._get_purchase_discount_fields() + discount_fields += [('discount4', _('Discount 4'))] + return discount_fields + +Usage +===== + +To set a partner default general discount you need to: + +1. Go to a partner and set the general discount in *Sales & Purchases* + tab. + +To set a general discount in a purchase order you need to: + +1. Create a purchase order. +2. Either select a partner with a purchase general discount defined or + set one in the summary section of the order. +3. This discount will be applied to every line. + +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 to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Tecnativa + +Contributors +------------ + +- `Tecnativa `__: + + - David Vidal + - Pedro M. Baeza + - Rafael Blasco + - Carlos Roca + - Pilar Vargas + +- `Aures TIC `__: + + - Jose Zambudio + - Anna Martinez + +- `Komit `__: + + - Cuong Nguyen Mtm + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/purchase-workflow `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/purchase_order_general_discount/__init__.py b/purchase_order_general_discount/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/purchase_order_general_discount/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/purchase_order_general_discount/__manifest__.py b/purchase_order_general_discount/__manifest__.py new file mode 100644 index 00000000000..54c588cdb9e --- /dev/null +++ b/purchase_order_general_discount/__manifest__.py @@ -0,0 +1,19 @@ +# Copyright 2019 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +{ + "name": "Purchase Order General Discount", + "summary": "General discount per purchase order", + "version": "18.0.1.0.0", + "category": "Purchases", + "website": "https://github.com/OCA/purchase-workflow", + "author": "Tecnativa, Odoo Community Association (OCA)", + "license": "AGPL-3", + "application": False, + "installable": True, + "depends": ["purchase"], + "data": [ + "views/purchase_order_view.xml", + "views/res_partner_view.xml", + "views/res_config_view.xml", + ], +} diff --git a/purchase_order_general_discount/i18n/es.po b/purchase_order_general_discount/i18n/es.po new file mode 100644 index 00000000000..fbf4b7325d3 --- /dev/null +++ b/purchase_order_general_discount/i18n/es.po @@ -0,0 +1,122 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_general_discount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 11.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2019-08-28 12:50+0000\n" +"PO-Revision-Date: 2023-12-29 10:35+0000\n" +"Last-Translator: Ivorra78 \n" +"Language-Team: \n" +"Language: es\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: purchase_order_general_discount +#: model_terms:ir.ui.view,arch_db:purchase_order_general_discount.res_config_settings_view_form_purchase +msgid "" +"" +msgstr "" +"" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_res_company +msgid "Companies" +msgstr "Compañías" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_res_partner +msgid "Contact" +msgstr "Contacto" + +#. module: purchase_order_general_discount +#. odoo-python +#: code:addons/purchase_order_general_discount/models/res_company.py:0 +#, python-format +msgid "Discount" +msgstr "Descuento" + +#. module: purchase_order_general_discount +#. odoo-python +#: code:addons/purchase_order_general_discount/models/res_company.py:0 +#, python-format +msgid "Discount 2" +msgstr "Descuento 2" + +#. module: purchase_order_general_discount +#. odoo-python +#: code:addons/purchase_order_general_discount/models/res_company.py:0 +#, python-format +msgid "Discount 3" +msgstr "Descuento 3" + +#. module: purchase_order_general_discount +#: model:ir.model.constraint,message:purchase_order_general_discount.constraint_purchase_order_general_discount_limit +msgid "Discount must be lower than 100%." +msgstr "El descuento debe ser menor del 100%." + +#. module: purchase_order_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_purchase_order__general_discount +msgid "Gen. Disc. (%)" +msgstr "Desc. Gen. (%)" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_res_config_settings +msgid "Procurement purchase grouping settings" +msgstr "Configuración de la agrupación de adquisición de compras" + +#. module: purchase_order_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_company__purchase_general_discount_field +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_config_settings__purchase_general_discount_field +msgid "Purchase Discount Field" +msgstr "Campo para Descuento General de compra" + +#. module: purchase_order_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_partner__purchase_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_users__purchase_general_discount +msgid "Purchase General Discount (%)" +msgstr "Descuento General de Compra (%)" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_purchase_order +msgid "Purchase Order" +msgstr "Pedido de compra" + +#. module: purchase_order_general_discount +#: model_terms:ir.ui.view,arch_db:purchase_order_general_discount.res_config_settings_view_form_purchase +msgid "" +"Select to which purchase line field will the purchase general discount be " +"propagated." +msgstr "" +"Escoja a qué campo del descuento de la línea de pedido se propagará el " +"descuento general." + +#. module: purchase_order_general_discount +#: model:ir.model.fields,help:purchase_order_general_discount.field_res_company__purchase_general_discount_field +#: model:ir.model.fields,help:purchase_order_general_discount.field_res_config_settings__purchase_general_discount_field +msgid "" +"Set the purchase line discount field in which the discounts will be applied." +msgstr "" +"Establecer el campo de descuento de la línea de pedido en el que se aplicará " +"el descuento." + +#. module: purchase_order_general_discount +#: model_terms:ir.ui.view,arch_db:purchase_order_general_discount.purchase_order_form +msgid "Update general discounts" +msgstr "Actualizar descuento general" + +#~ msgid "Field" +#~ msgstr "Campo" + +#~ msgid "res.config.settings" +#~ msgstr "res.config.settings" + +#~ msgid "Purchase Order Line" +#~ msgstr "Línea de pedido de compra" diff --git a/purchase_order_general_discount/i18n/it.po b/purchase_order_general_discount/i18n/it.po new file mode 100644 index 00000000000..b7a88d5694d --- /dev/null +++ b/purchase_order_general_discount/i18n/it.po @@ -0,0 +1,115 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_general_discount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2024-03-05 14:35+0000\n" +"Last-Translator: mymage \n" +"Language-Team: none\n" +"Language: it\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n != 1;\n" +"X-Generator: Weblate 4.17\n" + +#. module: purchase_order_general_discount +#: model_terms:ir.ui.view,arch_db:purchase_order_general_discount.res_config_settings_view_form_purchase +msgid "" +"" +msgstr "" +"" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_res_company +msgid "Companies" +msgstr "Aziende" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_res_partner +msgid "Contact" +msgstr "Contatto" + +#. module: purchase_order_general_discount +#. odoo-python +#: code:addons/purchase_order_general_discount/models/res_company.py:0 +#, python-format +msgid "Discount" +msgstr "Sconto" + +#. module: purchase_order_general_discount +#. odoo-python +#: code:addons/purchase_order_general_discount/models/res_company.py:0 +#, python-format +msgid "Discount 2" +msgstr "Sconto 2" + +#. module: purchase_order_general_discount +#. odoo-python +#: code:addons/purchase_order_general_discount/models/res_company.py:0 +#, python-format +msgid "Discount 3" +msgstr "Sconto 3" + +#. module: purchase_order_general_discount +#: model:ir.model.constraint,message:purchase_order_general_discount.constraint_purchase_order_general_discount_limit +msgid "Discount must be lower than 100%." +msgstr "Lo sconto deve essere minore del 100%." + +#. module: purchase_order_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_purchase_order__general_discount +msgid "Gen. Disc. (%)" +msgstr "Sc. gen. (%)" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_res_config_settings +msgid "Procurement purchase grouping settings" +msgstr "Impostazioni raggruppamento approvvigionamento acquisti" + +#. module: purchase_order_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_company__purchase_general_discount_field +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_config_settings__purchase_general_discount_field +msgid "Purchase Discount Field" +msgstr "Campo sconto acquisti" + +#. module: purchase_order_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_partner__purchase_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_users__purchase_general_discount +msgid "Purchase General Discount (%)" +msgstr "Sconto generale acquisti (%)" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_purchase_order +msgid "Purchase Order" +msgstr "Ordine di acquisto" + +#. module: purchase_order_general_discount +#: model_terms:ir.ui.view,arch_db:purchase_order_general_discount.res_config_settings_view_form_purchase +msgid "" +"Select to which purchase line field will the purchase general discount be " +"propagated." +msgstr "" +"Selezionare in quale campo nella riga ordine di acquisto verrà propagato lo " +"sconto generale." + +#. module: purchase_order_general_discount +#: model:ir.model.fields,help:purchase_order_general_discount.field_res_company__purchase_general_discount_field +#: model:ir.model.fields,help:purchase_order_general_discount.field_res_config_settings__purchase_general_discount_field +msgid "" +"Set the purchase line discount field in which the discounts will be applied." +msgstr "" +"Imposta il campo sconto sulla riga ordine d'acquisto dove lo sconto verrà " +"applicato." + +#. module: purchase_order_general_discount +#: model_terms:ir.ui.view,arch_db:purchase_order_general_discount.purchase_order_form +msgid "Update general discounts" +msgstr "Aggiorna sconti generali" + +#~ msgid "Config Settings" +#~ msgstr "Impostazioni configurazione" diff --git a/purchase_order_general_discount/i18n/pt.po b/purchase_order_general_discount/i18n/pt.po new file mode 100644 index 00000000000..25473e4476e --- /dev/null +++ b/purchase_order_general_discount/i18n/pt.po @@ -0,0 +1,115 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_general_discount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"PO-Revision-Date: 2021-03-03 17:45+0000\n" +"Last-Translator: Pedro Castro Silva \n" +"Language-Team: none\n" +"Language: pt\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=2; plural=n > 1;\n" +"X-Generator: Weblate 4.3.2\n" + +#. module: purchase_order_general_discount +#: model_terms:ir.ui.view,arch_db:purchase_order_general_discount.res_config_settings_view_form_purchase +msgid "" +"" +msgstr "" +"" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_res_company +msgid "Companies" +msgstr "Empresas" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_res_partner +msgid "Contact" +msgstr "Contacto" + +#. module: purchase_order_general_discount +#. odoo-python +#: code:addons/purchase_order_general_discount/models/res_company.py:0 +#, python-format +msgid "Discount" +msgstr "Desconto" + +#. module: purchase_order_general_discount +#. odoo-python +#: code:addons/purchase_order_general_discount/models/res_company.py:0 +#, python-format +msgid "Discount 2" +msgstr "Desconto 2" + +#. module: purchase_order_general_discount +#. odoo-python +#: code:addons/purchase_order_general_discount/models/res_company.py:0 +#, python-format +msgid "Discount 3" +msgstr "Desconto 3" + +#. module: purchase_order_general_discount +#: model:ir.model.constraint,message:purchase_order_general_discount.constraint_purchase_order_general_discount_limit +msgid "Discount must be lower than 100%." +msgstr "O desconto tem que ser inferior a 100%." + +#. module: purchase_order_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_purchase_order__general_discount +msgid "Gen. Disc. (%)" +msgstr "Desc. Ger. (%)" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_res_config_settings +msgid "Procurement purchase grouping settings" +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_company__purchase_general_discount_field +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_config_settings__purchase_general_discount_field +msgid "Purchase Discount Field" +msgstr "Campo de Desconto de Compra" + +#. module: purchase_order_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_partner__purchase_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_users__purchase_general_discount +msgid "Purchase General Discount (%)" +msgstr "Desconto Geral de Compra (%)" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_purchase_order +msgid "Purchase Order" +msgstr "Encomenda de Compra" + +#. module: purchase_order_general_discount +#: model_terms:ir.ui.view,arch_db:purchase_order_general_discount.res_config_settings_view_form_purchase +msgid "" +"Select to which purchase line field will the purchase general discount be " +"propagated." +msgstr "" +"Selecione para que campo de linha de compra será propagado o desconto geral " +"de compra." + +#. module: purchase_order_general_discount +#: model:ir.model.fields,help:purchase_order_general_discount.field_res_company__purchase_general_discount_field +#: model:ir.model.fields,help:purchase_order_general_discount.field_res_config_settings__purchase_general_discount_field +msgid "" +"Set the purchase line discount field in which the discounts will be applied." +msgstr "" +"Defina o campo de desconto de linha de compra ao qual serão aplicados os " +"descontos." + +#. module: purchase_order_general_discount +#: model_terms:ir.ui.view,arch_db:purchase_order_general_discount.purchase_order_form +msgid "Update general discounts" +msgstr "Atualizar descontos gerais" + +#~ msgid "Config Settings" +#~ msgstr "Parâmetros de Configuração" diff --git a/purchase_order_general_discount/i18n/purchase_order_general_discount.pot b/purchase_order_general_discount/i18n/purchase_order_general_discount.pot new file mode 100644 index 00000000000..4f850b74113 --- /dev/null +++ b/purchase_order_general_discount/i18n/purchase_order_general_discount.pot @@ -0,0 +1,103 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * purchase_order_general_discount +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 16.0\n" +"Report-Msgid-Bugs-To: \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_order_general_discount +#: model_terms:ir.ui.view,arch_db:purchase_order_general_discount.res_config_settings_view_form_purchase +msgid "" +"" +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_res_company +msgid "Companies" +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_res_partner +msgid "Contact" +msgstr "" + +#. module: purchase_order_general_discount +#. odoo-python +#: code:addons/purchase_order_general_discount/models/res_company.py:0 +#, python-format +msgid "Discount" +msgstr "" + +#. module: purchase_order_general_discount +#. odoo-python +#: code:addons/purchase_order_general_discount/models/res_company.py:0 +#, python-format +msgid "Discount 2" +msgstr "" + +#. module: purchase_order_general_discount +#. odoo-python +#: code:addons/purchase_order_general_discount/models/res_company.py:0 +#, python-format +msgid "Discount 3" +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.model.constraint,message:purchase_order_general_discount.constraint_purchase_order_general_discount_limit +msgid "Discount must be lower than 100%." +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_purchase_order__general_discount +msgid "Gen. Disc. (%)" +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_res_config_settings +msgid "Procurement purchase grouping settings" +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_company__purchase_general_discount_field +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_config_settings__purchase_general_discount_field +msgid "Purchase Discount Field" +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_partner__purchase_general_discount +#: model:ir.model.fields,field_description:purchase_order_general_discount.field_res_users__purchase_general_discount +msgid "Purchase General Discount (%)" +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.model,name:purchase_order_general_discount.model_purchase_order +msgid "Purchase Order" +msgstr "" + +#. module: purchase_order_general_discount +#: model_terms:ir.ui.view,arch_db:purchase_order_general_discount.res_config_settings_view_form_purchase +msgid "" +"Select to which purchase line field will the purchase general discount be " +"propagated." +msgstr "" + +#. module: purchase_order_general_discount +#: model:ir.model.fields,help:purchase_order_general_discount.field_res_company__purchase_general_discount_field +#: model:ir.model.fields,help:purchase_order_general_discount.field_res_config_settings__purchase_general_discount_field +msgid "" +"Set the purchase line discount field in which the discounts will be applied." +msgstr "" + +#. module: purchase_order_general_discount +#: model_terms:ir.ui.view,arch_db:purchase_order_general_discount.purchase_order_form +msgid "Update general discounts" +msgstr "" diff --git a/purchase_order_general_discount/models/__init__.py b/purchase_order_general_discount/models/__init__.py new file mode 100644 index 00000000000..eba22b70df1 --- /dev/null +++ b/purchase_order_general_discount/models/__init__.py @@ -0,0 +1,4 @@ +from . import purchase_order +from . import res_company +from . import res_config_settings +from . import res_partner diff --git a/purchase_order_general_discount/models/purchase_order.py b/purchase_order_general_discount/models/purchase_order.py new file mode 100644 index 00000000000..dacd2b82706 --- /dev/null +++ b/purchase_order_general_discount/models/purchase_order.py @@ -0,0 +1,68 @@ +# Copyright 2019 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import api, fields, models + + +class PurchaseOrder(models.Model): + _inherit = "purchase.order" + + general_discount = fields.Float( + digits="Discount", + string="Gen. Disc. (%)", + ) + + _sql_constraints = [ + ( + "general_discount_limit", + "CHECK (general_discount <= 100.0)", + "Discount must be lower than 100%.", + ), + ] + + @api.onchange("partner_id") + def onchange_partner_id(self): + res = super().onchange_partner_id() + self.general_discount = ( + self.partner_id.commercial_partner_id.purchase_general_discount + ) + return res + + def _get_general_discount_field(self): + """We can set in settings another discount field to be applied + For example, if we had purchase_triple_dicount, we could set the + general discount in discount3 to be applied after all other + discounts""" + discount_field = self.company_id.purchase_general_discount_field + return discount_field or "discount" + + @api.onchange("general_discount") + def onchange_general_discount(self): + discount_field = self._get_general_discount_field() + self.mapped("order_line").update({discount_field: self.general_discount}) + + def action_update_general_discount(self): + for order in self: + order.onchange_general_discount() + + @api.model + def _get_view(self, view_id=None, view_type="form", **options): + """The purpose of this is to write a context on "order_line" field + respecting other contexts on this field. + There is a PR (https://github.com/odoo/odoo/pull/26607) to odoo for + avoiding this. If merged, remove this method and add the attribute + in the field. + """ + arch, view = super()._get_view(view_id=view_id, view_type=view_type, **options) + if view_type == "form": + discount_field = self._get_general_discount_field() + order_line_fields = arch.xpath("//field[@name='order_line']") + if order_line_fields: + order_line_field = order_line_fields[0] + context = order_line_field.attrib.get("context", "{}").replace( + "{", + f"{{'default_{discount_field}': general_discount, ", + 1, + ) + order_line_field.attrib["context"] = context + return arch, view diff --git a/purchase_order_general_discount/models/res_company.py b/purchase_order_general_discount/models/res_company.py new file mode 100644 index 00000000000..7c644db50cd --- /dev/null +++ b/purchase_order_general_discount/models/res_company.py @@ -0,0 +1,32 @@ +# Copyright 2019 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import _, api, fields, models + + +class ResCompany(models.Model): + _inherit = "res.company" + + purchase_general_discount_field = fields.Selection( + selection="_get_purchase_discount_fields", + string="Purchase Discount Field", + default="discount", + help="Set the purchase line discount field in which the " + "discounts will be applied.", + ) + + @api.model + def _get_purchase_discount_fields(self): + """Extensible method to add possible discounts. We offer in advance + the posibility of using purchase_triple_discount so no bridge + module is needed""" + discount_fields = [("discount", _("Discount"))] + purchase_line_fields = self.env["purchase.order.line"]._fields.keys() + if "discount2" in purchase_line_fields: + discount_fields += [ + ("discount2", _("Discount 2")), + ] + if "discount3" in purchase_line_fields: + discount_fields += [ + ("discount3", _("Discount 3")), + ] + return discount_fields diff --git a/purchase_order_general_discount/models/res_config_settings.py b/purchase_order_general_discount/models/res_config_settings.py new file mode 100644 index 00000000000..55e163949b1 --- /dev/null +++ b/purchase_order_general_discount/models/res_config_settings.py @@ -0,0 +1,12 @@ +# Copyright 2019 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +from odoo import fields, models + + +class ResConfigSettings(models.TransientModel): + _inherit = "res.config.settings" + + purchase_general_discount_field = fields.Selection( + related="company_id.purchase_general_discount_field", + readonly=False, + ) diff --git a/purchase_order_general_discount/models/res_partner.py b/purchase_order_general_discount/models/res_partner.py new file mode 100644 index 00000000000..228c52bece1 --- /dev/null +++ b/purchase_order_general_discount/models/res_partner.py @@ -0,0 +1,14 @@ +# Copyright 2019 Tecnativa - David Vidal +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + purchase_general_discount = fields.Float( + digits="Discount", + string="Purchase General Discount (%)", + company_dependent=True, + ) diff --git a/purchase_order_general_discount/pyproject.toml b/purchase_order_general_discount/pyproject.toml new file mode 100644 index 00000000000..4231d0cccb3 --- /dev/null +++ b/purchase_order_general_discount/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/purchase_order_general_discount/readme/CONFIGURE.md b/purchase_order_general_discount/readme/CONFIGURE.md new file mode 100644 index 00000000000..9f1bdf0c955 --- /dev/null +++ b/purchase_order_general_discount/readme/CONFIGURE.md @@ -0,0 +1,22 @@ +You can set in settings another discount field to be applied. For +example, if we had purchase_triple_discount, we could set the general +discount in discount3 to be applied after all other discounts. + +To do so: + +1. Go to *Purchases \> Configuration \> Settings* and *Purchase + Discount Field* +2. Select the discount you'd wish to use. purchase_triple_discount + fields will appear when the module is installed. + +There's a method at res.company called \_get_purchase_discount_fields +that can be used to extend more line discount fields. For example, if we +had the field discount4, we could extend it like this: + +``` python +@api.model +def _get_purchase_discount_fields(self): + discount_fields = super()._get_purchase_discount_fields() + discount_fields += [('discount4', _('Discount 4'))] + return discount_fields +``` diff --git a/purchase_order_general_discount/readme/CONTRIBUTORS.md b/purchase_order_general_discount/readme/CONTRIBUTORS.md new file mode 100644 index 00000000000..c7ea55660ae --- /dev/null +++ b/purchase_order_general_discount/readme/CONTRIBUTORS.md @@ -0,0 +1,16 @@ +- [Tecnativa](https://www.tecnativa.com): + + > - David Vidal + > - Pedro M. Baeza + > - Rafael Blasco + > - Carlos Roca + > - Pilar Vargas + +- [Aures TIC](https://www.aurestic.es): + + > - Jose Zambudio + > - Anna Martinez + +- [Komit](https://komit-consulting.com): + + - Cuong Nguyen Mtm \<\> diff --git a/purchase_order_general_discount/readme/DESCRIPTION.md b/purchase_order_general_discount/readme/DESCRIPTION.md new file mode 100644 index 00000000000..79200b768f5 --- /dev/null +++ b/purchase_order_general_discount/readme/DESCRIPTION.md @@ -0,0 +1,5 @@ +This module allows to set a general discount in a purchase order. This +general discount is applied to each line order. + +You can also set a default general discount on suppliers and configure +to which line field the discount will be applied. diff --git a/purchase_order_general_discount/readme/USAGE.md b/purchase_order_general_discount/readme/USAGE.md new file mode 100644 index 00000000000..f4ceffd91e9 --- /dev/null +++ b/purchase_order_general_discount/readme/USAGE.md @@ -0,0 +1,11 @@ +To set a partner default general discount you need to: + +1. Go to a partner and set the general discount in *Sales & Purchases* + tab. + +To set a general discount in a purchase order you need to: + +1. Create a purchase order. +2. Either select a partner with a purchase general discount defined or + set one in the summary section of the order. +3. This discount will be applied to every line. diff --git a/purchase_order_general_discount/static/description/icon.png b/purchase_order_general_discount/static/description/icon.png new file mode 100644 index 00000000000..3a0328b516c Binary files /dev/null and b/purchase_order_general_discount/static/description/icon.png differ diff --git a/purchase_order_general_discount/static/description/index.html b/purchase_order_general_discount/static/description/index.html new file mode 100644 index 00000000000..df2bca105a4 --- /dev/null +++ b/purchase_order_general_discount/static/description/index.html @@ -0,0 +1,489 @@ + + + + + +Purchase Order General Discount + + + +
+

Purchase Order General Discount

+ + +

Beta License: AGPL-3 OCA/purchase-workflow Translate me on Weblate Try me on Runboat

+

This module allows to set a general discount in a purchase order. This +general discount is applied to each line order.

+

You can also set a default general discount on suppliers and configure +to which line field the discount will be applied.

+

Table of contents

+ +
+

Configuration

+

You can set in settings another discount field to be applied. For +example, if we had purchase_triple_discount, we could set the general +discount in discount3 to be applied after all other discounts.

+

To do so:

+
    +
  1. Go to Purchases > Configuration > Settings and Purchase Discount +Field
  2. +
  3. Select the discount you’d wish to use. purchase_triple_discount +fields will appear when the module is installed.
  4. +
+

There’s a method at res.company called _get_purchase_discount_fields +that can be used to extend more line discount fields. For example, if we +had the field discount4, we could extend it like this:

+
+@api.model
+def _get_purchase_discount_fields(self):
+    discount_fields = super()._get_purchase_discount_fields()
+    discount_fields += [('discount4', _('Discount 4'))]
+    return discount_fields
+
+
+
+

Usage

+

To set a partner default general discount you need to:

+
    +
  1. Go to a partner and set the general discount in Sales & Purchases +tab.
  2. +
+

To set a general discount in a purchase order you need to:

+
    +
  1. Create a purchase order.
  2. +
  3. Either select a partner with a purchase general discount defined or +set one in the summary section of the order.
  4. +
  5. This discount will be applied to every line.
  6. +
+
+
+

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 to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Tecnativa
  • +
+
+
+

Contributors

+ +
+
+

Maintainers

+

This module is maintained by the OCA.

+ +Odoo Community Association + +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/purchase-workflow project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/purchase_order_general_discount/tests/__init__.py b/purchase_order_general_discount/tests/__init__.py new file mode 100644 index 00000000000..f51e1fb3d51 --- /dev/null +++ b/purchase_order_general_discount/tests/__init__.py @@ -0,0 +1 @@ +from . import test_purchase_order_general_discount diff --git a/purchase_order_general_discount/tests/test_purchase_order_general_discount.py b/purchase_order_general_discount/tests/test_purchase_order_general_discount.py new file mode 100644 index 00000000000..dc7446bf941 --- /dev/null +++ b/purchase_order_general_discount/tests/test_purchase_order_general_discount.py @@ -0,0 +1,49 @@ +# Copyright 2019 Tecnativa - David Vidal +# Copyright 2022 Tecnativa - Pilar Vargas +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo.tests import Form, TransactionCase + + +class TestPurchaseOrderLineInput(TransactionCase): + @classmethod + def setUpClass(cls): + super().setUpClass() + cls.partner = cls.env["res.partner"].create( + {"name": "Test", "purchase_general_discount": 10.0} + ) + cls.product = cls.env["product.product"].create( + {"name": "test_product", "type": "service"} + ) + order_form = Form(cls.env["purchase.order"]) + order_form.partner_id = cls.partner + with order_form.order_line.new() as line_form: + line_form.product_id = cls.product + line_form.product_uom = cls.product.uom_id + line_form.product_qty = 1 + line_form.price_unit = 1000.00 + cls.order = order_form.save() + cls.View = cls.env["ir.ui.view"] + + def test_01_default_partner_discount(self): + self.order.onchange_partner_id() + self.assertEqual( + self.order.general_discount, self.partner.purchase_general_discount + ) + + def test_02_sale_order_values(self): + self.order.general_discount = 10 + self.order.action_update_general_discount() + self.assertEqual(self.order.order_line.price_subtotal, 900.00) + + def test_03_get_view_set_default_line_discount_value(self): + company = self.order.company_id + company.purchase_general_discount_field = "discount" + po_form_view_xmlid = "purchase_order_general_discount.purchase_order_form" + with Form(self.order, po_form_view_xmlid) as order_form: + order_form.general_discount = 8 + with order_form.order_line.edit(0) as line_form: + self.assertEqual(line_form.discount, 8) + order_form.general_discount = 10 + with order_form.order_line.edit(0) as line_form: + self.assertEqual(line_form.discount, 10) diff --git a/purchase_order_general_discount/views/purchase_order_view.xml b/purchase_order_general_discount/views/purchase_order_view.xml new file mode 100644 index 00000000000..253e50171a9 --- /dev/null +++ b/purchase_order_general_discount/views/purchase_order_view.xml @@ -0,0 +1,23 @@ + + + + + purchase.order + + + +
+
+ +
+
+
+
diff --git a/purchase_order_general_discount/views/res_config_view.xml b/purchase_order_general_discount/views/res_config_view.xml new file mode 100644 index 00000000000..37482e0c55a --- /dev/null +++ b/purchase_order_general_discount/views/res_config_view.xml @@ -0,0 +1,34 @@ + + + + + res.config.settings.view.form.inherit.purchase + res.config.settings + + + + +
+
+
+
+
+
+
+
diff --git a/purchase_order_general_discount/views/res_partner_view.xml b/purchase_order_general_discount/views/res_partner_view.xml new file mode 100644 index 00000000000..aadbe4ff159 --- /dev/null +++ b/purchase_order_general_discount/views/res_partner_view.xml @@ -0,0 +1,17 @@ + + + + + res.partner + + + + + + + +