diff --git a/base_global_discount/__manifest__.py b/base_global_discount/__manifest__.py
index 28ae4418..643cf338 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 10f5b294..556c2214 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 16a25aca..98455c5c 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 7adb4ae9..2e6c18ce 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 ddc55381..ff618aea 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 3023274e..6964a73f 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 be4aae3a..c9ef8652 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
+
+
-
+
-
+
-
-
-
+
+