-
-
Notifications
You must be signed in to change notification settings - Fork 63
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
17 changed files
with
765 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,87 @@ | ||
=============== | ||
Pending Coupons | ||
=============== | ||
|
||
.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
!! 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--promotion-lightgray.png?logo=github | ||
:target: https://github.com/OCA/sale-promotion/tree/13.0/sale_coupon_order_pending | ||
: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-13-0/sale-promotion-13-0-sale_coupon_order_pending | ||
:alt: Translate me on Weblate | ||
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png | ||
:target: https://runbot.odoo-community.org/runbot/296/13.0 | ||
:alt: Try me on Runbot | ||
|
||
|badge1| |badge2| |badge3| |badge4| |badge5| | ||
|
||
This module allows the salesmen to tell if there are pending coupons that customer can | ||
enjoy in his sales order. | ||
|
||
**Table of contents** | ||
|
||
.. contents:: | ||
:local: | ||
|
||
Usage | ||
===== | ||
|
||
To use this module, you need to: | ||
|
||
#. Generate some coupons for your partner. | ||
#. Go to a quotation/sales order from that partner and a smart button will show that | ||
there are pending coupons. | ||
#. Click on the smart button and you'll be able to apply those which conditions are met | ||
by the order. | ||
|
||
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 smashing it by providing a detailed and welcomed | ||
`feedback <https://github.com/OCA/sale-promotion/issues/new?body=module:%20sale_coupon_order_pending%0Aversion:%2013.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 | ||
~~~~~~~ | ||
|
||
* Tecnativa | ||
|
||
Contributors | ||
~~~~~~~~~~~~ | ||
|
||
* `Tecnativa <https://www.tecnativa.com>`_: | ||
|
||
* David Vidal | ||
|
||
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/13.0/sale_coupon_order_pending>`_ 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,13 @@ | ||
# Copyright 2023 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
{ | ||
"name": "Pending Coupons", | ||
"summary": "Show partner's pending coupons in sale order", | ||
"version": "13.0.1.0.0", | ||
"author": "Tecnativa, Odoo Community Association (OCA)", | ||
"license": "AGPL-3", | ||
"category": "Sales Management", | ||
"website": "https://github.com/OCA/sale-promotion", | ||
"depends": ["sale_coupon"], | ||
"data": ["views/sale_order_views.xml", "views/coupon_coupon_views.xml"], | ||
} |
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,2 @@ | ||
from . import coupon_coupon | ||
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,33 @@ | ||
# Copyright 2023 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import api, fields, models | ||
|
||
|
||
class SaleCoupon(models.Model): | ||
_inherit = "sale.coupon" | ||
|
||
can_be_applied_to_order = fields.Boolean( | ||
compute="_compute_can_be_applied_to_order", compute_sudo=True, | ||
) | ||
|
||
@api.depends_context("active_id") | ||
def _compute_can_be_applied_to_order(self): | ||
self.can_be_applied_to_order = False | ||
if self.env.context.get("active_model", "") != "sale.order": | ||
return | ||
order = self.env["sale.order"].browse(self.env.context.get("active_id")) | ||
for coupon in self: | ||
if not coupon._check_coupon_code(order): | ||
self.can_be_applied_to_order = True | ||
|
||
def action_apply_partner_coupon(self): | ||
if self.env.context.get("active_model", "") != "sale.order": | ||
return | ||
self.env["sale.coupon.apply.code"].sudo().new( | ||
{"coupon_code": self.code} | ||
).process_coupon() | ||
return ( | ||
self.env["sale.order"] | ||
.browse(self.env.context.get("active_id")) | ||
.get_formview_action() | ||
) |
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,54 @@ | ||
# Copyright 2023 Tecnativa - David Vidal | ||
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). | ||
from odoo import _, api, fields, models | ||
from odoo.osv import expression | ||
|
||
|
||
class SaleOrder(models.Model): | ||
_inherit = "sale.order" | ||
|
||
pending_partner_coupon_count = fields.Integer( | ||
compute="_compute_pending_partner_coupon_count", compute_sudo=True, | ||
) | ||
|
||
def _partner_coupon_domain(self): | ||
"""For compatibility with sale_coupon_apply_commercial_partner""" | ||
return [("partner_id", "=", self.partner_id.id)] | ||
|
||
def _pending_coupon_domain(self): | ||
"""Override to do a broader search""" | ||
return expression.AND( | ||
[ | ||
[("state", "=", "new"), ("order_id", "!=", self.id)], | ||
self._partner_coupon_domain(), | ||
] | ||
) | ||
|
||
@api.depends("partner_id") | ||
def _compute_pending_partner_coupon_count(self): | ||
"""Give a hint to the salesman about pending coupons for this parnter""" | ||
self.pending_partner_coupon_count = 0 | ||
for sale in self.filtered("partner_id"): | ||
sale.pending_partner_coupon_count = self.env["sale.coupon"].search_count( | ||
sale._pending_coupon_domain() | ||
) | ||
|
||
def action_view_pending_partner_coupons(self): | ||
"""View partner pending coupons""" | ||
self.ensure_one() | ||
coupon_obj = self.env["sale.coupon"] | ||
# Done for compatibility sake with sales_team_security | ||
if self.user_has_groups("sales_team.group_sale_salesman"): | ||
coupon_obj = coupon_obj.sudo() | ||
pending_partner_coupon_ids = coupon_obj._search(self._pending_coupon_domain()) | ||
return { | ||
"type": "ir.actions.act_window", | ||
"name": _( | ||
"Coupons pending for %(customer)s" % {"customer": self.partner_id.name} | ||
), | ||
"view_mode": "kanban,form", | ||
"res_model": "sale.coupon", | ||
"target": "current", | ||
"context": {"active_id": self.id, "active_model": "sale.order"}, | ||
"domain": [("id", "in", pending_partner_coupon_ids)], | ||
} |
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 @@ | ||
* `Tecnativa <https://www.tecnativa.com>`_: | ||
|
||
* David Vidal |
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,2 @@ | ||
This module allows the salesmen to tell if there are pending coupons that customer can | ||
enjoy in his sales 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,7 @@ | ||
To use this module, you need to: | ||
|
||
#. Generate some coupons for your partner. | ||
#. Go to a quotation/sales order from that partner and a smart button will show that | ||
there are pending coupons. | ||
#. Click on the smart button and you'll be able to apply those which conditions are met | ||
by the order. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.