From b215abe4f7758626ad6e4e45719b8c89c9554591 Mon Sep 17 00:00:00 2001 From: Ernesto Tejeda Date: Tue, 3 Nov 2020 19:07:07 -0500 Subject: [PATCH] [MIG] base_global_discount: Migration to 13.0 [UPD] Update base_global_discount.pot Update translation files Updated by "Update PO files to match POT (msgmerge)" hook in Weblate. Translation: server-backend-13.0/server-backend-13.0-base_global_discount Translate-URL: https://translation.odoo-community.org/projects/server-backend-13-0/server-backend-13-0-base_global_discount/ --- base_global_discount/README.rst | 16 ++++----- base_global_discount/__manifest__.py | 6 ++-- .../i18n/base_global_discount.pot | 11 +++--- base_global_discount/i18n/es.po | 4 +-- base_global_discount/i18n/pt.po | 6 ++-- .../migrations/13.0.1.0.0/post-migration.py | 36 +++++++++++++++++++ .../migrations/13.0.1.0.0/pre-migration.py | 13 +++++++ .../models/global_discount.py | 14 +++----- base_global_discount/models/res_partner.py | 2 ++ base_global_discount/readme/CONTRIBUTORS.rst | 1 + base_global_discount/readme/USAGE.rst | 5 ++- base_global_discount/security/security.xml | 2 +- .../tests/test_global_discount.py | 4 +-- .../views/global_discount_views.xml | 1 - .../views/res_partner_views.xml | 4 +-- 15 files changed, 85 insertions(+), 40 deletions(-) create mode 100644 base_global_discount/migrations/13.0.1.0.0/post-migration.py create mode 100644 base_global_discount/migrations/13.0.1.0.0/pre-migration.py diff --git a/base_global_discount/README.rst b/base_global_discount/README.rst index 57b66f6f..3996ceef 100644 --- a/base_global_discount/README.rst +++ b/base_global_discount/README.rst @@ -14,13 +14,13 @@ Base Global Discount :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html :alt: License: AGPL-3 .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fserver--backend-lightgray.png?logo=github - :target: https://github.com/OCA/server-backend/tree/12.0/base_global_discount + :target: https://github.com/OCA/server-backend/tree/13.0/base_global_discount :alt: OCA/server-backend .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png - :target: https://translation.odoo-community.org/projects/server-backend-12-0/server-backend-12-0-base_global_discount + :target: https://translation.odoo-community.org/projects/server-backend-13-0/server-backend-13-0-base_global_discount :alt: Translate me on Weblate .. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png - :target: https://runbot.odoo-community.org/runbot/253/12.0 + :target: https://runbot.odoo-community.org/runbot/253/13.0 :alt: Try me on Runbot |badge1| |badge2| |badge3| |badge4| |badge5| @@ -50,9 +50,8 @@ You can assign global discounts to partners as well: #. Go to a partner that is a company. #. Go to the *Sales & Purchases* tab. -#. In section sale (if the partner is a customer), you can set sale discounts. -#. In section purchase (if the partner is a supplier), you can set purchase - discounts. +#. In section sale, you can set sale discounts. +#. In section purchase, you can set purchase discounts. Bug Tracker =========== @@ -60,7 +59,7 @@ 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 smashing it by providing a detailed and welcomed -`feedback `_. +`feedback `_. Do not contact contributors directly about support or help with technical issues. @@ -81,6 +80,7 @@ Contributors * David Vidal * Carlos Dauden * Rafael Blasco + * Ernesto Tejeda Maintainers ~~~~~~~~~~~ @@ -95,6 +95,6 @@ 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/server-backend `_ project on GitHub. +This module is part of the `OCA/server-backend `_ project on GitHub. You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/base_global_discount/__manifest__.py b/base_global_discount/__manifest__.py index 643cf338..c16fc614 100644 --- a/base_global_discount/__manifest__.py +++ b/base_global_discount/__manifest__.py @@ -3,12 +3,12 @@ # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { "name": "Base Global Discount", - "version": "12.0.1.0.0", + "version": "13.0.1.0.0", "category": "Base", - "author": "Tecnativa," "Odoo Community Association (OCA)", + "author": "Tecnativa, Odoo Community Association (OCA)", "website": "https://github.com/OCA/server-backend", "license": "AGPL-3", - "depends": ["product",], + "depends": ["product"], "data": [ "security/ir.model.access.csv", "security/security.xml", diff --git a/base_global_discount/i18n/base_global_discount.pot b/base_global_discount/i18n/base_global_discount.pot index 6bf63b0c..58ce06fc 100644 --- a/base_global_discount/i18n/base_global_discount.pot +++ b/base_global_discount/i18n/base_global_discount.pot @@ -1,12 +1,12 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * base_global_discount +# * base_global_discount # msgid "" msgstr "" -"Project-Id-Version: Odoo Server 12.0\n" +"Project-Id-Version: Odoo Server 13.0\n" "Report-Msgid-Bugs-To: \n" -"Last-Translator: <>\n" +"Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" "Content-Type: text/plain; charset=UTF-8\n" @@ -98,7 +98,7 @@ msgid "Purchase Global Discounts" msgstr "" #. module: base_global_discount -#: selection:global.discount,discount_scope:0 +#: model:ir.model.fields.selection,name:base_global_discount.selection__global_discount__discount_scope__purchase msgid "Purchases" msgstr "" @@ -109,7 +109,7 @@ msgid "Sale Global Discounts" msgstr "" #. module: base_global_discount -#: selection:global.discount,discount_scope:0 +#: model:ir.model.fields.selection,name:base_global_discount.selection__global_discount__discount_scope__sale msgid "Sales" msgstr "" @@ -117,4 +117,3 @@ msgstr "" #: model:ir.model.fields,field_description:base_global_discount.field_global_discount__sequence msgid "Sequence" msgstr "" - diff --git a/base_global_discount/i18n/es.po b/base_global_discount/i18n/es.po index a66c0a72..e0e2e62f 100644 --- a/base_global_discount/i18n/es.po +++ b/base_global_discount/i18n/es.po @@ -101,7 +101,7 @@ msgid "Purchase Global Discounts" msgstr "Descuentos globales de compra" #. module: base_global_discount -#: selection:global.discount,discount_scope:0 +#: model:ir.model.fields.selection,name:base_global_discount.selection__global_discount__discount_scope__purchase msgid "Purchases" msgstr "Compras" @@ -112,7 +112,7 @@ msgid "Sale Global Discounts" msgstr "Descuentos de venta globales" #. module: base_global_discount -#: selection:global.discount,discount_scope:0 +#: model:ir.model.fields.selection,name:base_global_discount.selection__global_discount__discount_scope__sale msgid "Sales" msgstr "Ventas" diff --git a/base_global_discount/i18n/pt.po b/base_global_discount/i18n/pt.po index 6d100e8b..9d572acd 100644 --- a/base_global_discount/i18n/pt.po +++ b/base_global_discount/i18n/pt.po @@ -1,6 +1,6 @@ # Translation of Odoo Server. # This file contains the translation of the following modules: -# * base_global_discount +# * base_global_discount # msgid "" msgstr "" @@ -101,7 +101,7 @@ msgid "Purchase Global Discounts" msgstr "Descontos Globais de Compras" #. module: base_global_discount -#: selection:global.discount,discount_scope:0 +#: model:ir.model.fields.selection,name:base_global_discount.selection__global_discount__discount_scope__purchase msgid "Purchases" msgstr "Compras" @@ -112,7 +112,7 @@ msgid "Sale Global Discounts" msgstr "Descontos Globais de Vendas" #. module: base_global_discount -#: selection:global.discount,discount_scope:0 +#: model:ir.model.fields.selection,name:base_global_discount.selection__global_discount__discount_scope__sale msgid "Sales" msgstr "Vendas" diff --git a/base_global_discount/migrations/13.0.1.0.0/post-migration.py b/base_global_discount/migrations/13.0.1.0.0/post-migration.py new file mode 100644 index 00000000..0d3657bd --- /dev/null +++ b/base_global_discount/migrations/13.0.1.0.0/post-migration.py @@ -0,0 +1,36 @@ +# Copyright 2020 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from openupgradelib import openupgrade + + +@openupgrade.migrate() +def migrate(env, version): + openupgrade.logged_query( + env.cr, + """ + INSERT INTO customer_global_discount_rel + (partner_id, global_discount_id) + SELECT + partner_id, + global_discount_id + FROM + global_discount_res_partner_rel + WHERE + discount_scope = 'sale'; + """, + ) + openupgrade.logged_query( + env.cr, + """ + INSERT INTO supplier_global_discount_rel + (partner_id, global_discount_id) + SELECT + partner_id, + field_id + FROM + global_discount_res_partner_rel + WHERE + discount_scope = 'purchase'; + """, + ) diff --git a/base_global_discount/migrations/13.0.1.0.0/pre-migration.py b/base_global_discount/migrations/13.0.1.0.0/pre-migration.py new file mode 100644 index 00000000..88a9f7f9 --- /dev/null +++ b/base_global_discount/migrations/13.0.1.0.0/pre-migration.py @@ -0,0 +1,13 @@ +# Copyright 2020 Tecnativa - Ernesto Tejeda +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + + +def migrate(cr, version): + if not version: + return + cr.execute( + """ + DELETE FROM ir_model_relation + WHERE name = 'global_discount_res_partner_rel'; + """ + ) diff --git a/base_global_discount/models/global_discount.py b/base_global_discount/models/global_discount.py index 556c2214..60e6b69e 100644 --- a/base_global_discount/models/global_discount.py +++ b/base_global_discount/models/global_discount.py @@ -2,21 +2,17 @@ # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). from odoo import fields, models -from odoo.addons import decimal_precision as dp - class GlobalDiscount(models.Model): _name = "global.discount" _description = "Global Discount" _order = "sequence, id desc" - sequence = fields.Integer(help="Gives the order to apply discounts",) - name = fields.Char(string="Discount Name", required=True,) - discount = fields.Float( - digits=dp.get_precision("Discount"), required=True, default=0.0, - ) + sequence = fields.Integer(help="Gives the order to apply discounts") + name = fields.Char(string="Discount Name", required=True) + discount = fields.Float(digits="Discount", required=True, default=0.0) discount_scope = fields.Selection( - selection=[("sale", "Sales"), ("purchase", "Purchases"),], + selection=[("sale", "Sales"), ("purchase", "Purchases")], default="sale", required="True", string="Discount Scope", @@ -24,7 +20,7 @@ class GlobalDiscount(models.Model): company_id = fields.Many2one( comodel_name="res.company", string="Company", - default=lambda self: self.env.user.company_id, + default=lambda self: self.env.company, ) def name_get(self): diff --git a/base_global_discount/models/res_partner.py b/base_global_discount/models/res_partner.py index 98455c5c..1a01b992 100644 --- a/base_global_discount/models/res_partner.py +++ b/base_global_discount/models/res_partner.py @@ -8,6 +8,7 @@ class ResPartner(models.Model): customer_global_discount_ids = fields.Many2many( comodel_name="global.discount", + relation="customer_global_discount_rel", column1="partner_id", column2="global_discount_id", string="Sale Global Discounts", @@ -15,6 +16,7 @@ class ResPartner(models.Model): ) supplier_global_discount_ids = fields.Many2many( comodel_name="global.discount", + relation="supplier_global_discount_rel", column1="partner_id", column2="global_discount_id", string="Purchase Global Discounts", diff --git a/base_global_discount/readme/CONTRIBUTORS.rst b/base_global_discount/readme/CONTRIBUTORS.rst index 7b1dda35..872df73d 100644 --- a/base_global_discount/readme/CONTRIBUTORS.rst +++ b/base_global_discount/readme/CONTRIBUTORS.rst @@ -4,3 +4,4 @@ * David Vidal * Carlos Dauden * Rafael Blasco + * Ernesto Tejeda diff --git a/base_global_discount/readme/USAGE.rst b/base_global_discount/readme/USAGE.rst index 8d9135e4..5615b886 100644 --- a/base_global_discount/readme/USAGE.rst +++ b/base_global_discount/readme/USAGE.rst @@ -2,6 +2,5 @@ You can assign global discounts to partners as well: #. Go to a partner that is a company. #. Go to the *Sales & Purchases* tab. -#. In section sale (if the partner is a customer), you can set sale discounts. -#. In section purchase (if the partner is a supplier), you can set purchase - discounts. +#. In section sale, you can set sale discounts. +#. In section purchase, you can set purchase discounts. diff --git a/base_global_discount/security/security.xml b/base_global_discount/security/security.xml index 2e6c18ce..eeb722c6 100644 --- a/base_global_discount/security/security.xml +++ b/base_global_discount/security/security.xml @@ -7,7 +7,7 @@ ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] + >['|',('company_id','=',False),('company_id', 'in', company_ids)] diff --git a/base_global_discount/tests/test_global_discount.py b/base_global_discount/tests/test_global_discount.py index ff618aea..47ddd834 100644 --- a/base_global_discount/tests/test_global_discount.py +++ b/base_global_discount/tests/test_global_discount.py @@ -9,10 +9,10 @@ class TestGlobalDiscount(common.SavepointCase): super().setUpClass() cls.global_discount_obj = cls.env["global.discount"] cls.global_discount_1 = cls.global_discount_obj.create( - {"name": "Test Discount 1", "discount_scope": "sale", "discount": 20,} + {"name": "Test Discount 1", "discount_scope": "sale", "discount": 20} ) cls.global_discount_2 = cls.global_discount_obj.create( - {"name": "Test Discount 2", "discount_scope": "sale", "discount": 30,} + {"name": "Test Discount 2", "discount_scope": "sale", "discount": 30} ) def test_01_global_discounts(self): diff --git a/base_global_discount/views/global_discount_views.xml b/base_global_discount/views/global_discount_views.xml index 6964a73f..5cf4e77a 100644 --- a/base_global_discount/views/global_discount_views.xml +++ b/base_global_discount/views/global_discount_views.xml @@ -34,7 +34,6 @@ Global Discounts ir.actions.act_window global.discount - form tree,form