Skip to content

Commit c81b974

Browse files
MohamedOsman7yankinmax
authored andcommitted
[MIG] sale_fixed_discount: Migration to 18.0
1 parent 39c7e98 commit c81b974

11 files changed

Lines changed: 56 additions & 65 deletions

File tree

sale_fixed_discount/README.rst

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Sale Fixed Discount
77
!! This file is generated by oca-gen-addon-readme !!
88
!! changes will be overwritten. !!
99
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10-
!! source digest: sha256:6b49ea689315a0a5b3c5db1dbd0a6ea8c2400faad3943a6da1a547d929d4360d
10+
!! source digest: sha256:9fbc48c4968018c610d6befda6c7804ced8212bb8b51c5a1f3bb97d9cde0baad
1111
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1212
1313
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
@@ -17,13 +17,13 @@ Sale Fixed Discount
1717
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
1818
:alt: License: AGPL-3
1919
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github
20-
:target: https://github.com/OCA/sale-workflow/tree/17.0/sale_fixed_discount
20+
:target: https://github.com/OCA/sale-workflow/tree/18.0/sale_fixed_discount
2121
:alt: OCA/sale-workflow
2222
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23-
:target: https://translation.odoo-community.org/projects/sale-workflow-17-0/sale-workflow-17-0-sale_fixed_discount
23+
:target: https://translation.odoo-community.org/projects/sale-workflow-18-0/sale-workflow-18-0-sale_fixed_discount
2424
:alt: Translate me on Weblate
2525
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26-
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=17.0
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&target_branch=18.0
2727
:alt: Try me on Runboat
2828

2929
|badge1| |badge2| |badge3| |badge4| |badge5|
@@ -43,7 +43,7 @@ Installation
4343

4444
This module depends on module 'account_invoice_fixed_discount',
4545
available in
46-
https://github.com/OCA/account-invoicing/tree/17.0/account_invoice_fixed_discount
46+
https://github.com/OCA/account-invoicing/tree/18.0/account_invoice_fixed_discount
4747

4848
Configuration
4949
=============
@@ -69,7 +69,7 @@ Bug Tracker
6969
Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-workflow/issues>`_.
7070
In case of trouble, please check there if your issue has already been reported.
7171
If you spotted it first, help us to smash it by providing a detailed and welcomed
72-
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_fixed_discount%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
72+
`feedback <https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_fixed_discount%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
7373

7474
Do not contact contributors directly about support or help with technical issues.
7575

@@ -84,16 +84,16 @@ Authors
8484
Contributors
8585
------------
8686

87-
- Lois Rilo <lois.rilo@forgeflow.com>
88-
(`www.forgeflow.com <http://www.forgeflow.com>`__)
89-
- Jordi Ballester <jordi.ballester@forgeflow.com>
90-
(`www.forgeflow.com <http://www.forgeflow.com>`__)
91-
- Pieter Paulussen <pieterpaulussen@code-source.be>
92-
(`www.code-source.be <http://www.code-source.be>`__)
87+
- Lois Rilo <lois.rilo@forgeflow.com>
88+
(`www.forgeflow.com <http://www.forgeflow.com>`__)
89+
- Jordi Ballester <jordi.ballester@forgeflow.com>
90+
(`www.forgeflow.com <http://www.forgeflow.com>`__)
91+
- Pieter Paulussen <pieterpaulussen@code-source.be>
92+
(`www.code-source.be <http://www.code-source.be>`__)
9393

94-
- OERP Canada <https://www.oerp.ca/>:
94+
- OERP Canada <https://www.oerp.ca/>:
9595

96-
- Foram Darji <fd@oerp.ca>
96+
- Foram Darji <fd@oerp.ca>
9797

9898
Maintainers
9999
-----------
@@ -108,6 +108,6 @@ OCA, or the Odoo Community Association, is a nonprofit organization whose
108108
mission is to support the collaborative development of Odoo features and
109109
promote its widespread use.
110110

111-
This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/17.0/sale_fixed_discount>`_ project on GitHub.
111+
This module is part of the `OCA/sale-workflow <https://github.com/OCA/sale-workflow/tree/18.0/sale_fixed_discount>`_ project on GitHub.
112112

113113
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

sale_fixed_discount/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"name": "Sale Fixed Discount",
55
"summary": "Allows to apply fixed amount discounts in sales orders.",
6-
"version": "17.0.2.1.0",
6+
"version": "18.0.1.0.0",
77
"category": "Sales",
88
"website": "https://github.com/OCA/sale-workflow",
99
"author": "ForgeFlow, Odoo Community Association (OCA)",

sale_fixed_discount/i18n/sale_fixed_discount.pot

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#
55
msgid ""
66
msgstr ""
7-
"Project-Id-Version: Odoo Server 17.0\n"
7+
"Project-Id-Version: Odoo Server 18.0\n"
88
"Report-Msgid-Bugs-To: \n"
99
"Last-Translator: \n"
1010
"Language-Team: \n"
@@ -51,7 +51,6 @@ msgstr ""
5151
#. module: sale_fixed_discount
5252
#. odoo-python
5353
#: code:addons/sale_fixed_discount/models/sale_order_line.py:0
54-
#, python-format
5554
msgid ""
5655
"The fixed discount %(fixed)s does not match the calculateddiscount "
5756
"%(discount)s %%.Please correct one of the discounts."

sale_fixed_discount/models/sale_order_line.py

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright 2017-20 ForgeFlow S.L.
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

4-
from odoo import _, api, fields, models
4+
from odoo import api, fields, models
55
from odoo.exceptions import ValidationError
66
from odoo.tools.float_utils import float_compare, float_round
77

@@ -35,18 +35,16 @@ def _check_discounts(self):
3535
!= 0
3636
):
3737
raise ValidationError(
38-
_(
38+
self.env._(
3939
"The fixed discount %(fixed)s does not match the calculated"
4040
"discount %(discount)s %%."
41-
"Please correct one of the discounts."
41+
"Please correct one of the discounts.",
42+
fixed=line.discount_fixed,
43+
discount=line.discount,
4244
)
43-
% {
44-
"fixed": line.discount_fixed,
45-
"discount": line.discount,
46-
}
4745
)
4846

49-
def _convert_to_tax_base_line_dict(self, **kwargs):
47+
def _prepare_base_line_for_taxes_computation(self, **kwargs):
5048
"""Prior to calculating the tax toals for a line, update the discount value
5149
used in the tax calculation to the full float value. Otherwise, we get rounding
5250
errors in the resulting calculated totals.
@@ -63,20 +61,21 @@ def _convert_to_tax_base_line_dict(self, **kwargs):
6361

6462
# Accurately pass along the fixed discount amount to the tax computation method.
6563
if self.discount_fixed:
66-
return self.env["account.tax"]._convert_to_tax_base_line_dict(
64+
return self.env["account.tax"]._prepare_base_line_for_taxes_computation(
6765
self,
68-
partner=self.order_id.partner_id,
69-
currency=self.order_id.currency_id,
70-
product=self.product_id,
71-
taxes=self.tax_id,
72-
price_unit=self.price_unit,
73-
quantity=self.product_uom_qty,
74-
discount=self._get_discount_from_fixed_discount(),
75-
price_subtotal=self.price_subtotal,
76-
**kwargs,
66+
**{
67+
"tax_ids": self.tax_id,
68+
"quantity": self.product_uom_qty,
69+
"partner_id": self.order_id.partner_id,
70+
"currency_id": self.order_id.currency_id
71+
or self.order_id.company_id.currency_id,
72+
"rate": self.order_id.currency_rate,
73+
"discount": self._get_discount_from_fixed_discount(),
74+
**kwargs,
75+
},
7776
)
7877

79-
return super()._convert_to_tax_base_line_dict()
78+
return super()._prepare_base_line_for_taxes_computation(**kwargs)
8079

8180
@api.depends("discount_fixed", "price_unit")
8281
def _compute_discount(self):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
This module depends on module 'account_invoice_fixed_discount',
22
available in
3-
<https://github.com/OCA/account-invoicing/tree/17.0/account_invoice_fixed_discount>
3+
<https://github.com/OCA/account-invoicing/tree/18.0/account_invoice_fixed_discount>

sale_fixed_discount/security/res_groups.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8" ?>
22
<odoo noupdate="1">
3-
<record id="product.group_discount_per_so_line" model="res.groups">
3+
<record id="sale.group_discount_per_so_line" model="res.groups">
44
<field
55
name="implied_ids"
66
eval="[(4, ref('account_invoice_fixed_discount.group_fixed_discount'))]"

sale_fixed_discount/static/description/index.html

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -367,9 +367,9 @@ <h1 class="title">Sale Fixed Discount</h1>
367367
!! This file is generated by oca-gen-addon-readme !!
368368
!! changes will be overwritten. !!
369369
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
370-
!! source digest: sha256:6b49ea689315a0a5b3c5db1dbd0a6ea8c2400faad3943a6da1a547d929d4360d
370+
!! source digest: sha256:9fbc48c4968018c610d6befda6c7804ced8212bb8b51c5a1f3bb97d9cde0baad
371371
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
372-
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/sale-workflow/tree/17.0/sale_fixed_discount"><img alt="OCA/sale-workflow" src="https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sale-workflow-17-0/sale-workflow-17-0-sale_fixed_discount"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&amp;target_branch=17.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
372+
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/sale-workflow/tree/18.0/sale_fixed_discount"><img alt="OCA/sale-workflow" src="https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/sale-workflow-18-0/sale-workflow-18-0-sale_fixed_discount"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/sale-workflow&amp;target_branch=18.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
373373
<p>This module extends the functionality of Sales to allow you to apply
374374
fixed amount discount at sales order line level.</p>
375375
<p>The module also extends the sales order report to show fixed discount.</p>
@@ -392,7 +392,7 @@ <h1 class="title">Sale Fixed Discount</h1>
392392
<h1><a class="toc-backref" href="#toc-entry-1">Installation</a></h1>
393393
<p>This module depends on module ‘account_invoice_fixed_discount’,
394394
available in
395-
<a class="reference external" href="https://github.com/OCA/account-invoicing/tree/17.0/account_invoice_fixed_discount">https://github.com/OCA/account-invoicing/tree/17.0/account_invoice_fixed_discount</a></p>
395+
<a class="reference external" href="https://github.com/OCA/account-invoicing/tree/18.0/account_invoice_fixed_discount">https://github.com/OCA/account-invoicing/tree/18.0/account_invoice_fixed_discount</a></p>
396396
</div>
397397
<div class="section" id="configuration">
398398
<h1><a class="toc-backref" href="#toc-entry-2">Configuration</a></h1>
@@ -417,7 +417,7 @@ <h1><a class="toc-backref" href="#toc-entry-4">Bug Tracker</a></h1>
417417
<p>Bugs are tracked on <a class="reference external" href="https://github.com/OCA/sale-workflow/issues">GitHub Issues</a>.
418418
In case of trouble, please check there if your issue has already been reported.
419419
If you spotted it first, help us to smash it by providing a detailed and welcomed
420-
<a class="reference external" href="https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_fixed_discount%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
420+
<a class="reference external" href="https://github.com/OCA/sale-workflow/issues/new?body=module:%20sale_fixed_discount%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**">feedback</a>.</p>
421421
<p>Do not contact contributors directly about support or help with technical issues.</p>
422422
</div>
423423
<div class="section" id="credits">
@@ -452,7 +452,7 @@ <h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
452452
<p>OCA, or the Odoo Community Association, is a nonprofit organization whose
453453
mission is to support the collaborative development of Odoo features and
454454
promote its widespread use.</p>
455-
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/sale-workflow/tree/17.0/sale_fixed_discount">OCA/sale-workflow</a> project on GitHub.</p>
455+
<p>This module is part of the <a class="reference external" href="https://github.com/OCA/sale-workflow/tree/18.0/sale_fixed_discount">OCA/sale-workflow</a> project on GitHub.</p>
456456
<p>You are welcome to contribute. To learn how please visit <a class="reference external" href="https://odoo-community.org/page/Contribute">https://odoo-community.org/page/Contribute</a>.</p>
457457
</div>
458458
</div>

sale_fixed_discount/tests/test_sale_fixed_discount.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
33

44
from odoo.exceptions import ValidationError
5-
from odoo.tests import Form, TransactionCase
5+
from odoo.tests import Form
66

7+
from odoo.addons.base.tests.common import BaseCommon
78

8-
class TestSaleFixedDiscount(TransactionCase):
9+
10+
class TestSaleFixedDiscount(BaseCommon):
911
@classmethod
1012
def setUpClass(cls):
1113
super().setUpClass()
12-
cls.env.user.groups_id |= cls.env.ref("product.group_discount_per_so_line")
14+
cls.env.user.groups_id |= cls.env.ref("sale.group_discount_per_so_line")
1315
cls.partner = cls.env["res.partner"].create({"name": "Test"})
1416
cls.tax = cls.env["account.tax"].create(
1517
{
@@ -106,8 +108,8 @@ def test_03_fixed_discount_invoice(self):
106108
self.assertEqual(self.sale.invoice_ids.invoice_line_ids.discount_fixed, 20.0)
107109
self.assertEqual(self.sale.invoice_ids.invoice_line_ids.discount, 10.0)
108110

109-
self.assertEqual(self.sale.invoice_ids.tax_totals["amount_untaxed"], 180.0)
110-
self.assertEqual(self.sale.invoice_ids.tax_totals["amount_total"], 207.0)
111+
self.assertEqual(self.sale.invoice_ids.tax_totals["base_amount"], 180.0)
112+
self.assertEqual(self.sale.invoice_ids.tax_totals["total_amount"], 207.0)
111113

112114
def test_04_fixed_discount_without_price(self):
113115
with Form(self.sale) as sale_order:
@@ -131,5 +133,5 @@ def test_05_fixed_discount_invoice(self):
131133
self.assertEqual(self.sale.invoice_ids.invoice_line_ids.discount_fixed, 20.0)
132134
self.assertEqual(self.sale.invoice_ids.invoice_line_ids.discount, 10.0)
133135

134-
self.assertEqual(self.sale.invoice_ids.tax_totals["amount_untaxed"], 180.0)
135-
self.assertEqual(self.sale.invoice_ids.tax_totals["amount_total"], 207.0)
136+
self.assertEqual(self.sale.invoice_ids.tax_totals["base_amount"], 180.0)
137+
self.assertEqual(self.sale.invoice_ids.tax_totals["total_amount"], 207.0)

sale_fixed_discount/views/account_invoice_views.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<field name="inherit_id" ref="account_invoice_fixed_discount.view_move_form" />
88
<field name="arch" type="xml">
99
<field name="discount_fixed" position="attributes">
10-
<attribute name="groups">product.group_discount_per_so_line</attribute>
10+
<attribute name="groups">sale.group_discount_per_so_line</attribute>
1111
</field>
1212
</field>
1313
</record>

sale_fixed_discount/views/sale_order_views.xml

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,13 @@
1111
expr="//field[@name='order_line']/form//label[@for='discount']"
1212
position="before"
1313
>
14-
<field
15-
name="discount_fixed"
16-
groups="product.group_discount_per_so_line"
17-
/>
14+
<field name="discount_fixed" groups="sale.group_discount_per_so_line" />
1815
</xpath>
1916
<xpath
20-
expr="//field[@name='order_line']/tree/field[@name='discount']"
17+
expr="//field[@name='order_line']/list/field[@name='discount']"
2118
position="before"
2219
>
23-
<field
24-
name="discount_fixed"
25-
groups="product.group_discount_per_so_line"
26-
/>
20+
<field name="discount_fixed" groups="sale.group_discount_per_so_line" />
2721
</xpath>
2822
</field>
2923
</record>

0 commit comments

Comments
 (0)