[ADD] base_global_discount: New Module 11.0

This commit is contained in:
David
2019-08-21 12:36:02 +02:00
committed by Ernesto Tejeda
parent a1546d803d
commit b47b5ff22a
20 changed files with 715 additions and 0 deletions

View File

@@ -0,0 +1,2 @@
from . import global_discount
from . import res_partner

View File

@@ -0,0 +1,58 @@
# 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'
_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,
)
discount_scope = fields.Selection(
selection=[
('sale', 'Sales'),
('purchase', 'Purchases'),
],
default='sale',
required='True',
string='Discount Scope',
)
company_id = fields.Many2one(
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)))
return result
def _get_global_discount_vals(self, base, **kwargs):
""" Prepare the dict of values to create to obtain the discounted
amount
:param float base: the amount to discount
:return: dict with the discounted amount
"""
self.ensure_one()
return {
'global_discount': self,
'base': base,
'base_discounted': base * (1 - (self.discount / 100)),
}

View File

@@ -0,0 +1,22 @@
# Copyright 2019 Tecnativa - David Vidal
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class ResPartner(models.Model):
_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')],
)
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')],
)