Skip to content

Commit

Permalink
[NEW]sale_loyalty_ux: allows pricelist in rules
Browse files Browse the repository at this point in the history
  • Loading branch information
jok-adhoc committed Nov 28, 2023
1 parent 51b09ef commit 2eae5cf
Show file tree
Hide file tree
Showing 8 changed files with 179 additions and 0 deletions.
70 changes: 70 additions & 0 deletions sale_loyalty_ux/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
.. |company| replace:: ADHOC SA

.. |company_logo| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-logo.png
:alt: ADHOC SA
:target: https://www.adhoc.com.ar

.. |icon| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-icon.png

.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

===============
Sale Loyalty UX
===============



Installation
============

To install this module, you need to:

#. Just install this module

Configuration
=============

To configure this module, you need to:

#. No configuration needed

Usage
=====

To use this module, you need to:

#. This module add an exception to sale order to required Reference to confirm the sale order

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: http://runbot.adhoc.com.ar/

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

Bugs are tracked on `GitHub Issues
<https://github.com/ingadhoc/sale/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.

Credits
=======

Images
------

* |company| |icon|

Contributors
------------

Maintainer
----------

|company_logo|

This module is maintained by the |company|.

To contribute to this module, please visit https://www.adhoc.com.ar.
5 changes: 5 additions & 0 deletions sale_loyalty_ux/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################
from . import models
42 changes: 42 additions & 0 deletions sale_loyalty_ux/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
##############################################################################
#
# Copyright (C) 2015 ADHOC SA (http://www.adhoc.com.ar)
# All Rights Reserved.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
{
'name': 'Sale Loyalty UX',
'version': "16.0.1.0.0",
'category': 'Projects & Services',
'sequence': 14,
'summary': '',
'author': 'ADHOC SA',
'website': 'www.adhoc.com.ar',
'license': 'AGPL-3',
'images': [
],
'depends': [
'sale_loyalty',
],
'data': [
'views/loyalty_rule_views.xml',
],
'demo': [
],
'installable': True,
'auto_install': False,
'application': False,
}
3 changes: 3 additions & 0 deletions sale_loyalty_ux/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import loyalty_rule
from . import sale_order
from . import loyalty_program
17 changes: 17 additions & 0 deletions sale_loyalty_ux/models/loyalty_program.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from odoo import fields, models


class LoyaltyProgram(models.Model):
_inherit = 'loyalty.program'

def _get_valid_pricelists(self, pricelist):
'''
Returns a dict containing the pricelists that match per rule of the program
'''
rule_pricelists = dict()
for rule in self.rule_ids:
if not rule.pricelist_ids:
rule_pricelists[rule] = pricelist
else:
rule_pricelists[rule] = rule.pricelist_ids
return rule_pricelists
7 changes: 7 additions & 0 deletions sale_loyalty_ux/models/loyalty_rule.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import fields, models


class LoyaltyRule(models.Model):
_inherit = 'loyalty.rule'

pricelist_ids = fields.Many2many('product.pricelist', string='Pricelists')
22 changes: 22 additions & 0 deletions sale_loyalty_ux/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from odoo import models


class SaleOrder(models.Model):

_inherit = "sale.order"

def _program_check_compute_points(self, programs):
res = super()._program_check_compute_points(programs)
pricelist = self.pricelist_id
pricelists_per_rule = programs._get_valid_pricelists(pricelist)
aux_programs = programs
for program in programs:
aux_programs -= program
for rule in program.rule_ids:
if self.pricelist_id in pricelists_per_rule.get(rule):
aux_programs += program
break
for r in res:
if r not in aux_programs:
res[r] = {'error': "pricelist not matching"}
return res
13 changes: 13 additions & 0 deletions sale_loyalty_ux/views/loyalty_rule_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="loyalty_rule_view_form" model="ir.ui.view">
<field name="name">loyalty.rule.view.form</field>
<field name="model">loyalty.rule</field>
<field name="inherit_id" ref="loyalty.loyalty_rule_view_form"/>
<field name="arch" type="xml">
<field name="product_category_id" position="after">
<field name="pricelist_ids" string='Pricelists'/>
</field>
</field>
</record>
</odoo>

0 comments on commit 2eae5cf

Please sign in to comment.