build: configurar herramientas de verificación OCA
- Instalar pre-commit con 25 hooks configurados - Configurar black 26.1.0 para formateo de código Python - Configurar isort 7.0.0 para ordenación de imports - Configurar flake8 7.3.0 con flake8-bugbear - Configurar pylint 3.1.1 con pylint-odoo 9.1.2 - Añadir autoflake y pyupgrade para mejoras automáticas - Configurar prettier para formateo de XML/JSON/YAML - Crear .editorconfig para consistencia de editor - Crear Makefile con comandos útiles - Crear check_addon.sh para verificación rápida de addons - Actualizar configuración de VS Code con extensiones recomendadas - Añadir documentación completa de uso - Aplicar formateo automático a archivos existentes - Deshabilitar setuptools-odoo (no soporta Odoo 18.0 aún) - Deshabilitar fix-encoding-pragma (obsoleto, usar pyupgrade)
This commit is contained in:
parent
5b9c6e3211
commit
fe137dc265
224 changed files with 18376 additions and 0 deletions
|
|
@ -0,0 +1,82 @@
|
|||
# Copyright 2017-19 Tecnativa - David Vidal
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||
import functools
|
||||
|
||||
from odoo import api
|
||||
from odoo import fields
|
||||
from odoo import models
|
||||
|
||||
|
||||
class TripleDiscountMixin(models.AbstractModel):
|
||||
_name = "purchase.triple.discount.mixin"
|
||||
_description = "Purchase Triple Discount Mixin"
|
||||
|
||||
discount = fields.Float(
|
||||
compute="_compute_discount",
|
||||
store=True,
|
||||
)
|
||||
discount1 = fields.Float(
|
||||
string="Disc. 1 (%)",
|
||||
digits="Discount",
|
||||
readonly=False,
|
||||
)
|
||||
|
||||
discount2 = fields.Float(
|
||||
string="Disc. 2 (%)",
|
||||
digits="Discount",
|
||||
readonly=False,
|
||||
)
|
||||
discount3 = fields.Float(
|
||||
string="Disc. 3 (%)",
|
||||
digits="Discount",
|
||||
readonly=False,
|
||||
)
|
||||
|
||||
_sql_constraints = [
|
||||
(
|
||||
"discount1_limit",
|
||||
"CHECK (discount1 <= 100.0)",
|
||||
"Discount 1 must be lower than 100%.",
|
||||
),
|
||||
(
|
||||
"discount2_limit",
|
||||
"CHECK (discount2 <= 100.0)",
|
||||
"Discount 2 must be lower than 100%.",
|
||||
),
|
||||
(
|
||||
"discount3_limit",
|
||||
"CHECK (discount3 <= 100.0)",
|
||||
"Discount 3 must be lower than 100%.",
|
||||
),
|
||||
]
|
||||
|
||||
@api.depends(lambda self: self._get_multiple_discount_field_names())
|
||||
def _compute_discount(self):
|
||||
for record in self:
|
||||
record.discount = record._get_aggregated_discount_from_values(
|
||||
{
|
||||
fname: record[fname]
|
||||
for fname in record._get_multiple_discount_field_names()
|
||||
}
|
||||
)
|
||||
|
||||
def _get_aggregated_discount_from_values(self, values):
|
||||
discount_fnames = self._get_multiple_discount_field_names()
|
||||
discounts = []
|
||||
for discount_fname in discount_fnames:
|
||||
discounts.append(values.get(discount_fname) or 0.0)
|
||||
return self._get_aggregated_multiple_discounts(discounts)
|
||||
|
||||
@staticmethod
|
||||
def _get_multiple_discount_field_names():
|
||||
return ["discount1", "discount2", "discount3"]
|
||||
|
||||
@staticmethod
|
||||
def _get_aggregated_multiple_discounts(discounts):
|
||||
discount_values = []
|
||||
for discount in discounts:
|
||||
discount_values.append(1 - (discount or 0.0) / 100.0)
|
||||
aggregated_discount = (
|
||||
1 - functools.reduce((lambda x, y: x * y), discount_values)
|
||||
) * 100
|
||||
return aggregated_discount
|
||||
Loading…
Add table
Add a link
Reference in a new issue