Browse Source

[IMP] base_global_discount: black, isort, prettier

14.0
Ernesto Tejeda 4 years ago
committed by Omar (Comunitea)
parent
commit
bfda1e6a6a
  1. 31
      base_global_discount/__manifest__.py
  2. 42
      base_global_discount/models/global_discount.py
  3. 22
      base_global_discount/models/res_partner.py
  4. 18
      base_global_discount/security/security.xml
  5. 28
      base_global_discount/tests/test_global_discount.py
  6. 34
      base_global_discount/views/global_discount_views.xml
  7. 28
      base_global_discount/views/res_partner_views.xml

31
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,
}

42
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)),
}

22
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")],
)

18
base_global_discount/security/security.xml

@ -1,16 +1,16 @@
<?xml version="1.0"?>
<?xml version="1.0" ?>
<!-- Copyright 2019 Tecnativa - David Vidal
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record model="ir.rule" id="global_discount_comp_rule">
<field name="name">Global Discount multi-company</field>
<field name="model_id" ref="base_global_discount.model_global_discount"/>
<field name="domain_force">['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
<field name="perm_read" eval="1"/>
<field name="perm_create" eval="1"/>
<field name="perm_write" eval="1"/>
<field name="perm_unlink" eval="1"/>
<field name="model_id" ref="base_global_discount.model_global_discount" />
<field
name="domain_force"
>['|',('company_id','=',False),('company_id','child_of',[user.company_id.id])]</field>
<field name="perm_read" eval="1" />
<field name="perm_create" eval="1" />
<field name="perm_write" eval="1" />
<field name="perm_unlink" eval="1" />
</record>
</odoo>

28
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)

34
base_global_discount/views/global_discount_views.xml

@ -1,38 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2019 Tecnativa - David Vidal
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record id="global_discount_view_tree" model="ir.ui.view">
<field name="model">global.discount</field>
<field name="arch" type="xml">
<tree string="Global Discounts" editable="bottom">
<field name="sequence" widget="handle"/>
<field name="name"/>
<field name="discount"/>
<field name="discount_scope"/>
<field name="company_id"/>
<field name="sequence" widget="handle" />
<field name="name" />
<field name="discount" />
<field name="discount_scope" />
<field name="company_id" />
</tree>
</field>
</record>
<record id="global_discount_view_form" model="ir.ui.view">
<field name="model">global.discount</field>
<field name="arch" type="xml">
<form string="Global Discounts">
<sheet>
<group col="4">
<field name="name"/>
<field name="sequence"/>
<field name="discount"/>
<field name="discount_scope"/>
<field name="company_id"/>
<field name="name" />
<field name="sequence" />
<field name="discount" />
<field name="discount_scope" />
<field name="company_id" />
</group>
</sheet>
</form>
</field>
</record>
<record id="action_global_discount_tree" model="ir.actions.act_window">
<field name="name">Global Discounts</field>
<field name="type">ir.actions.act_window</field>
@ -40,10 +37,11 @@
<field name="view_type">form</field>
<field name="view_mode">tree,form</field>
</record>
<menuitem id="menu_global_discount"
<menuitem
id="menu_global_discount"
action="action_global_discount_tree"
name="Global Discounts"
sequence="1" parent="base.menu_ir_property"/>
sequence="1"
parent="base.menu_ir_property"
/>
</odoo>

28
base_global_discount/views/res_partner_views.xml

@ -1,21 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2019 Tecnativa - David Vidal
License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). -->
<odoo>
<record model="ir.ui.view" id="res_partner_form_view">
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<group name="sale" position="inside">
<field name="customer_global_discount_ids" widget="many2many_tags"
attrs="{'invisible': [('customer', '=', False), ('is_company', '=', False), ('parent_id', '!=', False)]}"/>
<field
name="customer_global_discount_ids"
widget="many2many_tags"
attrs="{'invisible': [('customer', '=', False), ('is_company', '=', False), ('parent_id', '!=', False)]}"
/>
</group>
<group name="purchase" position="inside">
<field name="supplier_global_discount_ids" widget="many2many_tags"
attrs="{'invisible': [('supplier', '=', False), ('is_company', '=', False), ('parent_id', '!=', False)]}"/>
<field
name="supplier_global_discount_ids"
widget="many2many_tags"
attrs="{'invisible': [('supplier', '=', False), ('is_company', '=', False), ('parent_id', '!=', False)]}"
/>
</group>
</field>
</record>
</field>
</record>
</odoo>
Loading…
Cancel
Save