nuevo addon para calcular el precio con descuento antes del impuesto cuando se funciona con precios B2C, es una diferencia de un céntimo en cada línea, pero hay contables quisquillosos.

Sobreescribe compute_all de sale.order.line, seguramente cause problemas si se usan más addons que toquen el descuento.
This commit is contained in:
santiky 2021-09-04 19:34:02 +02:00
parent 4e8a423a5a
commit 3cadaade3c
Signed by: snt
GPG key ID: A9FD34930EADBE71
4 changed files with 48 additions and 0 deletions

View file

@ -0,0 +1 @@
from . import models

View file

@ -0,0 +1,14 @@
# Copyright 2021 Criptomart
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Sale Calc Discount B2C',
'summary': 'When prices are tax included, calculates the discount in price excluding tax.',
'version': '12.0.1.0.0',
'author': 'Criptomart',
'depends': [
'sale',
],
'installable': True,
'auto_install': False,
'application': False,
}

View file

@ -0,0 +1 @@
from . import sale

View file

@ -0,0 +1,32 @@
# Copyright (C) 2021: Criptomart (<https://criptomart.net/>)
# @author: Criptomart (<tech@criptomart.net>)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
#import logging
from odoo import models, fields, api
#_logger = logging.getLogger(__name__)
class SaleOrderOrderLine(models.Model):
_inherit = 'sale.order.line'
@api.depends('product_uom_qty', 'discount', 'price_unit', 'tax_id')
def _compute_amount(self):
"""
Compute the amounts of the SO line.
"""
for line in self:
price = line.price_unit
taxes = line.tax_id.compute_all(price, line.order_id.currency_id, line.product_uom_qty, product=line.product_id, partner=line.order_id.partner_shipping_id)
if line.discount:
price_disc = taxes['total_excluded'] * (1 - (line.discount or 0.0) / 100.0)
ctx = dict(self.env.context, force_price_include=False)
taxes = line.tax_id.with_context(ctx).compute_all(price_disc, line.order_id.currency_id, line.product_uom_qty, product=line.product_id, partner=line.order_id.partner_shipping_id)
line.update({
'price_tax': sum(t.get('amount', 0.0) for t in taxes.get('taxes', [])),
'price_total': taxes['total_included'],
'price_subtotal': taxes['total_excluded'],
})