-
-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by pedrobaeza
- Loading branch information
Showing
12 changed files
with
795 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
================== | ||
Loyalty Order Info | ||
================== | ||
|
||
.. | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! This file is generated by oca-gen-addon-readme !! | ||
!! changes will be overwritten. !! | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! source digest: sha256:8080e371d5afb278f95c163f92a7cf5f74c249c0fe7d8aff1052a6f86aef75e2 | ||
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
.. |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--promotion-lightgray.png?logo=github | ||
:target: https://github.com/OCA/sale-promotion/tree/16.0/sale_loyalty_order_info | ||
:alt: OCA/sale-promotion | ||
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png | ||
:target: https://translation.odoo-community.org/projects/sale-promotion-16-0/sale-promotion-16-0-sale_loyalty_order_info | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png | ||
:target: https://runboat.odoo-community.org/builds?repo=OCA/sale-promotion&target_branch=16.0 | ||
:alt: Try me on Runboat | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module provides more info on the applied loyalty rewards on a sale order. | ||
It provides: | ||
* The total reward amount, computed tax included; | ||
* A list of the applied promo codes; | ||
* All generated coupons from this sale order; | ||
* All programs applied to the sale order. | ||
|
||
The main goal is to use these info for reporting, so they are not added in views, as it would trigger additional computations. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Bug Tracker | ||
=========== | ||
|
||
Bugs are tracked on `GitHub Issues <https://github.com/OCA/sale-promotion/issues>`_. | ||
In case of trouble, please check there if your issue has already been reported. | ||
If you spotted it first, help us to smash it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/sale-promotion/issues/new?body=module:%20sale_loyalty_order_info%0Aversion:%2016.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 | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* `Acsone <https://www.acsone.eu>`_ | ||
|
||
* Marie Lejeune <[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-promotion <https://github.com/OCA/sale-promotion/tree/16.0/sale_loyalty_order_info>`_ project on GitHub. | ||
|
||
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import models |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Loyalty Order Info", | ||
"summary": "Add info on sale order about applied loyalties", | ||
"version": "16.0.1.0.0", | ||
"category": "Sale", | ||
"website": "https://github.com/OCA/sale-promotion", | ||
"author": "Acsone, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"depends": ["sale_loyalty"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from . import sale_order |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Copyright 2023 ACSONE SA/NV | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
from odoo import api, fields, models | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = "sale.order" | ||
|
||
reward_amount_tax_incl = fields.Float(compute="_compute_reward_total_tax_incl") | ||
promo_codes = fields.Char(compute="_compute_promo_codes") | ||
generated_coupon_ids = fields.One2many( | ||
"loyalty.card", | ||
"order_id", | ||
"Generated Coupons", | ||
help="The coupons generated from this order.", | ||
) | ||
program_ids = fields.Many2many( | ||
"loyalty.program", string="Applied programs", compute="_compute_programs" | ||
) | ||
|
||
def _get_reward_lines(self): | ||
self.ensure_one() | ||
return self.order_line.filtered("is_reward_line") | ||
|
||
@api.depends("order_line") | ||
def _compute_reward_total_tax_incl(self): | ||
for order in self: | ||
reward_amount_tax_incl = 0 | ||
for line in order._get_reward_lines(): | ||
if line.reward_id.reward_type != "product": | ||
reward_amount_tax_incl += line.price_subtotal + line.price_tax | ||
else: | ||
# Free product are 'regular' product lines with | ||
# a price_subtotal and price_tax of 0 | ||
reward_amount_tax_incl -= line.product_id.taxes_id.compute_all( | ||
line.product_id.lst_price, | ||
product=line.product_id, | ||
quantity=line.product_uom_qty, | ||
)["total_included"] | ||
order.reward_amount_tax_incl = reward_amount_tax_incl | ||
|
||
@api.depends("order_line", "applied_coupon_ids", "code_enabled_rule_ids") | ||
def _compute_promo_codes(self): | ||
for order in self: | ||
codes = order.applied_coupon_ids.mapped( | ||
"code" | ||
) + order.code_enabled_rule_ids.mapped("code") | ||
if codes: | ||
order.promo_codes = str(codes) # stock the list of codes in a string | ||
else: | ||
order.promo_codes = "[]" | ||
|
||
@api.depends("order_line", "applied_coupon_ids", "code_enabled_rule_ids") | ||
def _compute_programs(self): | ||
self.program_ids = self.env["loyalty.program"] | ||
for order in self: | ||
order.program_ids = order.order_line.reward_id.program_id |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* `Acsone <https://www.acsone.eu>`_ | ||
|
||
* Marie Lejeune <[email protected]> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
This module provides more info on the applied loyalty rewards on a sale order. | ||
It provides: | ||
* The total reward amount, computed tax included; | ||
* A list of the applied promo codes; | ||
* All generated coupons from this sale order; | ||
* All programs applied to the sale order. | ||
|
||
The main goal is to use these info for reporting, so they are not added in views, as it would trigger additional computations. |
Oops, something went wrong.