Skip to content

Commit

Permalink
[IMP] coupon_criteria_multi_product: pre-commit stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
ernesto-garcia-tecnativa committed Oct 12, 2023
1 parent 5d162b1 commit 215eeb5
Show file tree
Hide file tree
Showing 10 changed files with 86 additions and 45 deletions.
6 changes: 3 additions & 3 deletions loyalty_criteria_multi_product/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
{
"name": "Coupons multi product criteria",
"summary": "Allows to set as promotion criteria multi-product conditions",
"version": "15.0.1.0.0",
"version": "16.0.1.0.0",
"development_status": "Production/Stable",
"category": "Sale",
"website": "https://github.com/OCA/sale-promotion",
"author": "Tecnativa, Odoo Community Association (OCA)",
"maintainers": ["chienandalu"],
"license": "AGPL-3",
"depends": ["coupon"],
"data": ["views/sale_coupon_program_views.xml", "security/ir.model.access.csv"],
"depends": ["loyalty"],
"data": ["views/loyalty_rule_views.xml", "security/ir.model.access.csv"],
}
5 changes: 3 additions & 2 deletions loyalty_criteria_multi_product/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import coupon_criteria
from . import coupon_program
from . import rule_criteria
from . import loyalty_rule
from . import loyalty_program
19 changes: 19 additions & 0 deletions loyalty_criteria_multi_product/models/loyalty_program.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright 2021 Tecnativa - David Vidal
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
from odoo import models


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

def _get_valid_products(self, products):
"""
Returns a dict containing the products that match per rule of the program
"""
rule_products = super()._get_valid_products(products)
for rule in self.rule_ids:
if rule.rule_criteria_ids and rule.rule_criteria_ids[0].repeat_product:
rule_products[rule] = products
if not all([x in products for x in rule.rule_criteria_ids.product_ids]):
rule_products[rule] = self.env["product.product"]
return rule_products
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
from odoo import api, fields, models


class CouponProgram(models.Model):
_inherit = "coupon.program"
class LoyaltyRule(models.Model):
_inherit = "loyalty.rule"

coupon_criteria = fields.Selection(
rule_criteria = fields.Selection(
selection=[("domain", "Domain"), ("multi_product", "Multi Product")],
string="Coupon criteria",
string="Rule criteria",
help="- Domain: Standard behavior. The products are evaluated by domain.\n"
"- Multi product: different rules can be applied to different products "
"and all of the have to be fulfilled",
default="domain",
)
coupon_criteria_ids = fields.One2many(
rule_criteria_ids = fields.One2many(
string="Multi Product Criterias",
comodel_name="coupon.criteria",
inverse_name="program_id",
comodel_name="rule.criteria",
inverse_name="rule_id",
)

@api.onchange("coupon_criteria")
Expand All @@ -36,3 +36,12 @@ def _get_valid_products_multi_product(self, products, criteria):
if not all([x in products for x in criteria.product_ids]):
return self.env["product.product"]
return criteria.product_ids

def _get_valid_product_domain(self):
self.ensure_one()
if self.rule_criteria == "multi_product":
result_domain = [("id", "in", self.rule_criteria_ids.product_ids.ids)]
else:
result_domain = super()._get_valid_product_domain()

return result_domain
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
from odoo.exceptions import ValidationError


class CouponCriteria(models.Model):
_name = "coupon.criteria"
class RuleCriteria(models.Model):
_name = "rule.criteria"
_description = "Coupon Multi Product Criteria"

program_id = fields.Many2one(
comodel_name="coupon.program",
rule_id = fields.Many2one(
comodel_name="loyalty.rule",
)
rule_min_quantity = fields.Integer(
string="Min. Quantity",
Expand Down
4 changes: 2 additions & 2 deletions loyalty_criteria_multi_product/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
access_criteria_salesman,salesman,model_coupon_criteria,sales_team.group_sale_salesman,1,0,0,0
access_criteria_manager,criteria manager,model_coupon_criteria,sales_team.group_sale_manager,1,1,1,1
access_criteria_salesman,salesman,model_rule_criteria,sales_team.group_sale_salesman,1,0,0,0
access_criteria_manager,criteria manager,model_rule_criteria,sales_team.group_sale_manager,1,1,1,1
32 changes: 32 additions & 0 deletions loyalty_criteria_multi_product/views/loyalty_rule_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="loyalty_rule_view_form" model="ir.ui.view">
<field name="model">loyalty.rule</field>
<field name="inherit_id" ref="loyalty.loyalty_rule_view_form" />
<field name="arch" type="xml">
<field name="product_domain" position="before">
<field name="rule_criteria" widget="radio" />
<field
name="rule_criteria_ids"
attrs="{'invisible': [('rule_criteria', '!=', 'multi_product')]}"
>
<tree editable="bottom">
<field name="rule_min_quantity" string="Qty" />
<field name="product_ids" widget="many2many_tags" />
<field name="repeat_product" />
</tree>
</field>
</field>
<field name="product_domain" position="attributes">
<attribute
name="attrs"
>{'invisible': [('rule_criteria', '!=', 'domain')]}</attribute>
</field>
<field name="product_ids" position="attributes">
<attribute
name="attrs"
>{'invisible': [('rule_criteria', '!=', 'domain')]}</attribute>
</field>
</field>
</record>
</odoo>
27 changes: 0 additions & 27 deletions loyalty_criteria_multi_product/views/sale_coupon_program_views.xml

This file was deleted.

6 changes: 6 additions & 0 deletions setup/loyalty_criteria_multi_product/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)

0 comments on commit 215eeb5

Please sign in to comment.