From bfda1e6a6afc5621dd022a5f9100fb3baeea6a47 Mon Sep 17 00:00:00 2001 From: Ernesto Tejeda Date: Tue, 3 Nov 2020 11:05:41 -0500 Subject: [PATCH] [IMP] base_global_discount: black, isort, prettier --- base_global_discount/__manifest__.py | 31 +++++++------- .../models/global_discount.py | 42 +++++++------------ base_global_discount/models/res_partner.py | 22 +++++----- base_global_discount/security/security.xml | 18 ++++---- .../tests/test_global_discount.py | 28 ++++++------- .../views/global_discount_views.xml | 34 +++++++-------- .../views/res_partner_views.xml | 28 +++++++------ 7 files changed, 94 insertions(+), 109 deletions(-) diff --git a/base_global_discount/__manifest__.py b/base_global_discount/__manifest__.py index 28ae4418e..643cf338a 100644 --- a/base_global_discount/__manifest__.py +++ b/base_global_discount/__manifest__.py @@ -2,22 +2,19 @@ # Copyright 2020 Xtendoo - Manuel Calero # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). { - 'name': 'Base Global Discount', - 'version': '12.0.1.0.0', - 'category': 'Base', - 'author': 'Tecnativa,' - 'Odoo Community Association (OCA)', - 'website': 'https://github.com/OCA/server-backend', - 'license': 'AGPL-3', - 'depends': [ - 'product', + "name": "Base Global Discount", + "version": "12.0.1.0.0", + "category": "Base", + "author": "Tecnativa," "Odoo Community Association (OCA)", + "website": "https://github.com/OCA/server-backend", + "license": "AGPL-3", + "depends": ["product",], + "data": [ + "security/ir.model.access.csv", + "security/security.xml", + "views/global_discount_views.xml", + "views/res_partner_views.xml", ], - 'data': [ - 'security/ir.model.access.csv', - 'security/security.xml', - 'views/global_discount_views.xml', - 'views/res_partner_views.xml', - ], - 'application': False, - 'installable': True, + "application": False, + "installable": True, } diff --git a/base_global_discount/models/global_discount.py b/base_global_discount/models/global_discount.py index 10f5b294b..556c22149 100644 --- a/base_global_discount/models/global_discount.py +++ b/base_global_discount/models/global_discount.py @@ -1,46 +1,36 @@ # Copyright 2019 Tecnativa - David Vidal # 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' + _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, - ) + 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, + digits=dp.get_precision("Discount"), required=True, default=0.0, ) discount_scope = fields.Selection( - selection=[ - ('sale', 'Sales'), - ('purchase', 'Purchases'), - ], - default='sale', - required='True', - string='Discount Scope', + selection=[("sale", "Sales"), ("purchase", "Purchases"),], + default="sale", + required="True", + string="Discount Scope", ) company_id = fields.Many2one( - comodel_name='res.company', - string='Company', + comodel_name="res.company", + string="Company", default=lambda self: self.env.user.company_id, ) def name_get(self): result = [] for one in self: - result.append( - (one.id, '{} ({:.2f}%)'.format(one.name, one.discount))) + result.append((one.id, "{} ({:.2f}%)".format(one.name, one.discount))) return result def _get_global_discount_vals(self, base, **kwargs): @@ -52,7 +42,7 @@ class GlobalDiscount(models.Model): """ self.ensure_one() return { - 'global_discount': self, - 'base': base, - 'base_discounted': base * (1 - (self.discount / 100)), + "global_discount": self, + "base": base, + "base_discounted": base * (1 - (self.discount / 100)), } diff --git a/base_global_discount/models/res_partner.py b/base_global_discount/models/res_partner.py index 16a25acaf..98455c5c1 100644 --- a/base_global_discount/models/res_partner.py +++ b/base_global_discount/models/res_partner.py @@ -4,19 +4,19 @@ from odoo import fields, models class ResPartner(models.Model): - _inherit = 'res.partner' + _inherit = "res.partner" customer_global_discount_ids = fields.Many2many( - comodel_name='global.discount', - column1='partner_id', - column2='global_discount_id', - string='Sale Global Discounts', - domain=[('discount_scope', '=', 'sale')], + comodel_name="global.discount", + column1="partner_id", + column2="global_discount_id", + string="Sale Global Discounts", + domain=[("discount_scope", "=", "sale")], ) supplier_global_discount_ids = fields.Many2many( - comodel_name='global.discount', - column1='partner_id', - column2='global_discount_id', - string='Purchase Global Discounts', - domain=[('discount_scope', '=', 'purchase')], + comodel_name="global.discount", + column1="partner_id", + column2="global_discount_id", + string="Purchase Global Discounts", + domain=[("discount_scope", "=", "purchase")], ) diff --git a/base_global_discount/security/security.xml b/base_global_discount/security/security.xml index 7adb4ae9e..2e6c18cef 100644 --- a/base_global_discount/security/security.xml +++ b/base_global_discount/security/security.xml @@ -1,16 +1,16 @@ - + - Global Discount multi-company - - ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] - - - - + + ['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])] + + + + - diff --git a/base_global_discount/tests/test_global_discount.py b/base_global_discount/tests/test_global_discount.py index ddc553816..ff618aeaa 100644 --- a/base_global_discount/tests/test_global_discount.py +++ b/base_global_discount/tests/test_global_discount.py @@ -4,30 +4,26 @@ from odoo.tests import common class TestGlobalDiscount(common.SavepointCase): - @classmethod def setUpClass(cls): 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, - }) - cls.global_discount_2 = cls.global_discount_obj.create({ - 'name': 'Test Discount 2', - 'discount_scope': 'sale', - 'discount': 30, - }) + 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,} + ) + cls.global_discount_2 = cls.global_discount_obj.create( + {"name": "Test Discount 2", "discount_scope": "sale", "discount": 30,} + ) def test_01_global_discounts(self): """Chain two discounts of different types""" discount_vals = self.global_discount_1._get_global_discount_vals(100.0) - self.assertAlmostEqual(discount_vals['base_discounted'], 80.0) + self.assertAlmostEqual(discount_vals["base_discounted"], 80.0) discount_vals = self.global_discount_2._get_global_discount_vals( - discount_vals['base_discounted']) - self.assertAlmostEqual(discount_vals['base_discounted'], 56.0) + discount_vals["base_discounted"] + ) + self.assertAlmostEqual(discount_vals["base_discounted"], 56.0) def test_02_display_name(self): """Test that the name is computed fine""" - self.assertTrue('%)' in self.global_discount_1.display_name) + self.assertTrue("%)" in self.global_discount_1.display_name) diff --git a/base_global_discount/views/global_discount_views.xml b/base_global_discount/views/global_discount_views.xml index 3023274ee..6964a73fa 100644 --- a/base_global_discount/views/global_discount_views.xml +++ b/base_global_discount/views/global_discount_views.xml @@ -1,38 +1,35 @@ - + - global.discount - - - - - + + + + + - global.discount
- - - - - + + + + +
- Global Discounts ir.actions.act_window @@ -40,10 +37,11 @@ form tree,form - - - + sequence="1" + parent="base.menu_ir_property" + />
diff --git a/base_global_discount/views/res_partner_views.xml b/base_global_discount/views/res_partner_views.xml index be4aae3a8..c9ef86523 100644 --- a/base_global_discount/views/res_partner_views.xml +++ b/base_global_discount/views/res_partner_views.xml @@ -1,21 +1,25 @@ - + - - res.partner - - + res.partner + + - + - + - - - + +