Skip to content

Commit

Permalink
[MIG] sale_fixed_discount: Migration to 15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Rad0van committed Nov 21, 2022
1 parent be6996c commit f99d3d2
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 4 deletions.
2 changes: 1 addition & 1 deletion sale_fixed_discount/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
{
"name": "Sale Fixed Discount",
"summary": "Allows to apply fixed amount discounts in sales orders.",
"version": "13.0.1.1.1",
"version": "15.0.1.1.1",
"category": "Sales",
"website": "https:/OCA/sale-workflow",
"author": "ForgeFlow, Odoo Community Association (OCA)",
Expand Down
47 changes: 46 additions & 1 deletion sale_fixed_discount/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright 2017-20 ForgeFlow S.L.
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

import json

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError

Expand Down Expand Up @@ -55,7 +57,50 @@ def _compute_amount(self):
line.update(vals[line])
return res

def _prepare_invoice_line(self):
def _prepare_invoice_line(self, **optional_values):
res = super(SaleOrderLine, self)._prepare_invoice_line()
res.update({"discount_fixed": self.discount_fixed})
return res


class SaleOrder(models.Model):
_inherit = "sale.order"

@api.depends(
"order_line.tax_id", "order_line.price_unit", "amount_total", "amount_untaxed"
)
def _compute_tax_totals_json(self):
def compute_taxes(order_line):
real_price = order_line.price_unit * (
1 - (order_line.discount or 0.0) / 100.0
) - (order_line.discount_fixed or 0.0)
twicked_price = real_price / (1 - (order_line.discount or 0.0) / 100.0)
price = (
order_line.price_unit * (1 - (order_line.discount or 0.0) / 100.0)
if not order_line.discount_fixed
else twicked_price
)
order = order_line.order_id
return order_line.tax_id._origin.compute_all(
price,
order.currency_id,
order_line.product_uom_qty,
product=order_line.product_id,
partner=order.partner_shipping_id,
)

account_move = self.env["account.move"]
for order in self:
tax_lines_data = (
account_move._prepare_tax_lines_data_for_totals_from_object(
order.order_line, compute_taxes
)
)
tax_totals = account_move._get_tax_totals(
order.partner_id,
tax_lines_data,
order.amount_total,
order.amount_untaxed,
order.currency_id,
)
order.tax_totals_json = json.dumps(tax_totals)
4 changes: 2 additions & 2 deletions sale_fixed_discount/tests/test_sale_fixed_discount.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo.exceptions import ValidationError
from odoo.tests import SavepointCase
from odoo.tests import TransactionCase


class TestSaleFixedDiscount(SavepointCase):
class TestSaleFixedDiscount(TransactionCase):
@classmethod
def setUpClass(cls):
super(TestSaleFixedDiscount, cls).setUpClass()
Expand Down
1 change: 1 addition & 0 deletions sale_fixed_discount/views/sale_portal_templates.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<template
id="sale_order_portal_content_fixed_discount"
inherit_id="sale.sale_order_portal_content"
priority="100"
>
<xpath
expr="//section[@id='details']//t[@t-set='display_discount']"
Expand Down

0 comments on commit f99d3d2

Please sign in to comment.