From 3cadaade3ce3e1e741ea0e3faac7c038ddec7f06 Mon Sep 17 00:00:00 2001 From: santiky Date: Sat, 4 Sep 2021 19:34:02 +0200 Subject: [PATCH] =?UTF-8?q?nuevo=20addon=20para=20calcular=20el=20precio?= =?UTF-8?q?=20con=20descuento=20antes=20del=20impuesto=20cuando=20se=20fun?= =?UTF-8?q?ciona=20con=20precios=20B2C,=20es=20una=20diferencia=20de=20un?= =?UTF-8?q?=20c=C3=A9ntimo=20en=20cada=20l=C3=ADnea,=20pero=20hay=20contab?= =?UTF-8?q?les=20quisquillosos.=20Sobreescribe=20compute=5Fall=20de=20sale?= =?UTF-8?q?.order.line,=20seguramente=20cause=20problemas=20si=20se=20usan?= =?UTF-8?q?=20m=C3=A1s=20addons=20que=20toquen=20el=20descuento.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sale_calc_discount_b2c/__init__.py | 1 + sale_calc_discount_b2c/__manifest__.py | 14 ++++++++++ sale_calc_discount_b2c/models/__init__.py | 1 + sale_calc_discount_b2c/models/sale.py | 32 +++++++++++++++++++++++ 4 files changed, 48 insertions(+) create mode 100644 sale_calc_discount_b2c/__init__.py create mode 100644 sale_calc_discount_b2c/__manifest__.py create mode 100644 sale_calc_discount_b2c/models/__init__.py create mode 100644 sale_calc_discount_b2c/models/sale.py diff --git a/sale_calc_discount_b2c/__init__.py b/sale_calc_discount_b2c/__init__.py new file mode 100644 index 0000000..0650744 --- /dev/null +++ b/sale_calc_discount_b2c/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/sale_calc_discount_b2c/__manifest__.py b/sale_calc_discount_b2c/__manifest__.py new file mode 100644 index 0000000..c735c40 --- /dev/null +++ b/sale_calc_discount_b2c/__manifest__.py @@ -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, +} diff --git a/sale_calc_discount_b2c/models/__init__.py b/sale_calc_discount_b2c/models/__init__.py new file mode 100644 index 0000000..8a0dc04 --- /dev/null +++ b/sale_calc_discount_b2c/models/__init__.py @@ -0,0 +1 @@ +from . import sale diff --git a/sale_calc_discount_b2c/models/sale.py b/sale_calc_discount_b2c/models/sale.py new file mode 100644 index 0000000..4c359fb --- /dev/null +++ b/sale_calc_discount_b2c/models/sale.py @@ -0,0 +1,32 @@ +# Copyright (C) 2021: Criptomart () +# @author: Criptomart () +# 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'], + })