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

[16.0] [ADD] sale_loyalty_order_info: New module #177

Merged
merged 1 commit into from
Jan 16, 2024
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
85 changes: 85 additions & 0 deletions sale_loyalty_order_info/README.rst
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.
1 change: 1 addition & 0 deletions sale_loyalty_order_info/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
12 changes: 12 additions & 0 deletions sale_loyalty_order_info/__manifest__.py
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"],
}
1 change: 1 addition & 0 deletions sale_loyalty_order_info/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import sale_order
57 changes: 57 additions & 0 deletions sale_loyalty_order_info/models/sale_order.py
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(

Check warning on line 35 in sale_loyalty_order_info/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

sale_loyalty_order_info/models/sale_order.py#L35

Added line #L35 was not covered by tests
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
3 changes: 3 additions & 0 deletions sale_loyalty_order_info/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Acsone <https://www.acsone.eu>`_

* Marie Lejeune <[email protected]>
8 changes: 8 additions & 0 deletions sale_loyalty_order_info/readme/DESCRIPTION.rst
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.
Loading
Loading