Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][MIG] sale_promotion_rule_display_discount_amount #1586

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
92 changes: 92 additions & 0 deletions sale_promotion_rule_display_discount_amount/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
===========================================
Sale Promotion Rule Display Discount Amount
===========================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fsale--workflow-lightgray.png?logo=github
:target: https:/OCA/sale-workflow/tree/10.0/sale_promotion_rule_display_discount_amount
:alt: OCA/sale-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/sale-workflow-10-0/sale-workflow-10-0-sale_promotion_rule_display_discount_amount
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/167/10.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

Once the addon 'sale_discount_display_amount' is installed, the total wihout
discount ant the value of the discount is displayed on the sale orders. These
amounts are computed from the rate of the discount applied on each sale order
line.
Nevertheless, once you use the 'sale_promotion_rule' a discount amount
can be applied on a sale order. This new kind of discount is materialized by a
new line automatically to the sale order line with a specific product and a
negative amount.
The goal of this addon is to also take into account this kind of discount into
the total without discount and the value of the discount on the sale order.

**Table of contents**

.. contents::
:local:

Usage
=====


To use this module, you need to:

#. Go on a sale order
#. Set a discount on a line
#. The value of the discount is dislayed in the total section as well as the total without it.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https:/OCA/sale-workflow/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https:/OCA/sale-workflow/issues/new?body=module:%20sale_promotion_rule_display_discount_amount%0Aversion:%2010.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* ACSONE SA/NV

Contributors
~~~~~~~~~~~~

* Cédric Pigeon <[email protected]>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

This module is part of the `OCA/sale-workflow <https:/OCA/sale-workflow/tree/10.0/sale_promotion_rule_display_discount_amount>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions sale_promotion_rule_display_discount_amount/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
15 changes: 15 additions & 0 deletions sale_promotion_rule_display_discount_amount/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Copyright 2019-2021 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Sale Promotion Rule Display Discount Amount",
"summary": """
This addon allows you to display the amount of the discount applied by
the sale promotion rules on the sale order""",
"version": "14.0.1.0.0",
"development_status": "Beta",
"license": "AGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"website": "https:/OCA/sale-workflow",
"depends": ["sale_promotion_rule", "sale_discount_display_amount"],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_order
60 changes: 60 additions & 0 deletions sale_promotion_rule_display_discount_amount/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright 2019-2021 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, models
from odoo.tools import float_compare


class SaleOrder(models.Model):

_inherit = "sale.order"

@api.model
def _get_compute_discount_total_domain(self):
res = super()._get_compute_discount_total_domain()
res.extend(
[
"order_line.is_promotion_line",
"order_line.currency_id",
"currency_id",
]
)
return res

def _compute_discount_total(self):
super()._compute_discount_total()
for order in self:
discount_total = order.discount_total
price_total_no_discount = order.price_total_no_discount
if not order.order_line:
continue
for line in order.order_line:
if not line.is_promotion_line:
continue
price_total = line.price_total
if (
float_compare(
line.price_total,
0.0,
precision_rounding=line.currency_id.rounding,
)
< 1
):
price_total = -price_total
discount_total += price_total
price_total_no_discount += price_total

if (
float_compare(
discount_total,
order.discount_total,
precision_rounding=order.currency_id.rounding,
)
!= 0
):
order.update(
{
"discount_total": discount_total,
"price_total_no_discount": price_total_no_discount,
}
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Laurent Mignon <[email protected]>
* Xavier Bouquiaux <[email protected]>
10 changes: 10 additions & 0 deletions sale_promotion_rule_display_discount_amount/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Once the addon 'sale_discount_display_amount' is installed, the total wihout
discount ant the value of the discount is displayed on the sale orders. These
amounts are computed from the rate of the discount applied on each sale order
line.
Nevertheless, once you use the 'sale_promotion_rule' a discount amount
can be applied on a sale order. This new kind of discount is materialized by a
new line automatically to the sale order line with a specific product and a
negative amount.
The goal of this addon is to also take into account this kind of discount into
the total without discount and the value of the discount on the sale order.
6 changes: 6 additions & 0 deletions sale_promotion_rule_display_discount_amount/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

To use this module, you need to:

#. Go on a sale order
#. Set a discount on a line
#. The value of the discount is dislayed in the total section as well as the total without it.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading