From e023a0026e2e9a337adeec89021d5ade849ac0e6 Mon Sep 17 00:00:00 2001
From: dsolanki
Date: Fri, 16 Apr 2021 12:18:10 +0530
Subject: [PATCH] [IMP] black, isort, prettier.
---
pos_loyalty/__manifest__.py | 50 ++-
pos_loyalty/demo/templates.xml | 4 +-
pos_loyalty/models/loyalty_program.py | 51 +--
pos_loyalty/models/loyalty_reward.py | 109 +++---
pos_loyalty/models/loyalty_rule.py | 60 ++--
pos_loyalty/models/pos_config.py | 11 +-
pos_loyalty/models/pos_order.py | 19 +-
pos_loyalty/models/pos_order_line.py | 9 +-
pos_loyalty/models/res_partner.py | 9 +-
pos_loyalty/static/src/css/pos.css | 9 +-
pos_loyalty/static/src/js/pos.js | 396 ++++++++++++---------
pos_loyalty/static/src/js/tests.js | 269 ++++++++------
pos_loyalty/static/src/xml/pos.xml | 69 ++--
pos_loyalty/tests/__init__.py | 1 -
pos_loyalty/tests/test_pos_loyalty.py | 110 +++---
pos_loyalty/views/loyalty_program_view.xml | 56 ++-
pos_loyalty/views/loyalty_reward_view.xml | 48 ++-
pos_loyalty/views/loyalty_rule_view.xml | 24 +-
pos_loyalty/views/pos_config_view.xml | 8 +-
pos_loyalty/views/pos_order_view.xml | 6 +-
pos_loyalty/views/res_partner_view.xml | 14 +-
pos_loyalty/views/templates.xml | 6 +-
setup/pos_loyalty/odoo/addons/pos_loyalty | 1 +
setup/pos_loyalty/setup.py | 6 +
24 files changed, 784 insertions(+), 561 deletions(-)
create mode 120000 setup/pos_loyalty/odoo/addons/pos_loyalty
create mode 100644 setup/pos_loyalty/setup.py
diff --git a/pos_loyalty/__manifest__.py b/pos_loyalty/__manifest__.py
index b7e7f5188b..15d57723fe 100644
--- a/pos_loyalty/__manifest__.py
+++ b/pos_loyalty/__manifest__.py
@@ -4,33 +4,27 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
- 'name': 'Loyalty Program',
- 'version': '12.0.1.0.0',
- 'category': 'Point of Sale',
- 'license': 'AGPL-3',
- 'author': "OpenERP SA, "
- "RGB Consulting SL, "
- "Lambda IS, "
- "Odoo Community Association (OCA)",
- 'website': "https://odoo-community.org/",
- 'depends': ['point_of_sale'],
- 'demo': [
- 'demo/templates.xml',
+ "name": "Loyalty Program",
+ "version": "12.0.1.0.0",
+ "category": "Point of Sale",
+ "license": "AGPL-3",
+ "author": "OpenERP SA, "
+ "RGB Consulting SL, "
+ "Lambda IS, "
+ "Odoo Community Association (OCA)",
+ "website": "https://odoo-community.org/",
+ "depends": ["point_of_sale"],
+ "demo": ["demo/templates.xml"],
+ "data": [
+ "security/ir.model.access.csv",
+ "views/templates.xml",
+ "views/loyalty_program_view.xml",
+ "views/loyalty_reward_view.xml",
+ "views/loyalty_rule_view.xml",
+ "views/pos_config_view.xml",
+ "views/pos_order_view.xml",
+ "views/res_partner_view.xml",
],
- 'data': [
- 'security/ir.model.access.csv',
- 'views/templates.xml',
- 'views/loyalty_program_view.xml',
- 'views/loyalty_reward_view.xml',
- 'views/loyalty_rule_view.xml',
- 'views/pos_config_view.xml',
- 'views/pos_order_view.xml',
- 'views/res_partner_view.xml',
- ],
-
- 'qweb': [
- 'static/src/xml/pos.xml',
- ],
-
- 'installable': True,
+ "qweb": ["static/src/xml/pos.xml"],
+ "installable": True,
}
diff --git a/pos_loyalty/demo/templates.xml b/pos_loyalty/demo/templates.xml
index 81f834eb57..a7e84be2cf 100644
--- a/pos_loyalty/demo/templates.xml
+++ b/pos_loyalty/demo/templates.xml
@@ -1,8 +1,8 @@
-
+
-
+
diff --git a/pos_loyalty/models/loyalty_program.py b/pos_loyalty/models/loyalty_program.py
index a3493bebff..9c2d9dd3b5 100644
--- a/pos_loyalty/models/loyalty_program.py
+++ b/pos_loyalty/models/loyalty_program.py
@@ -6,25 +6,34 @@
class LoyaltyProgram(models.Model):
- _name = 'loyalty.program'
+ _name = "loyalty.program"
- name = fields.Char(string='Loyalty Program Name', size=32, index=True,
- required=True)
- pp_currency = fields.Float(string='Points per currency',
- help='Amount of loyalty points given to the '
- 'customer per sold currency')
- pp_product = fields.Float(string='Points per product',
- help='Amount of loyalty points given to the '
- 'customer per product sold')
- pp_order = fields.Float(string='Points per order',
- help='Amount of loyalty points given to the '
- 'customer for each point of sale order')
- rounding = fields.Float(string='Points Rounding', default=1,
- help='Loyalty point amounts will be rounded to '
- 'multiples of this value')
- rule_ids = fields.One2many(comodel_name='loyalty.rule',
- inverse_name='loyalty_program_id',
- string='Rules')
- reward_ids = fields.One2many(comodel_name='loyalty.reward',
- inverse_name='loyalty_program_id',
- string='Rewards')
+ name = fields.Char(
+ string="Loyalty Program Name", size=32, index=True, required=True
+ )
+ pp_currency = fields.Float(
+ string="Points per currency",
+ help="Amount of loyalty points given to the " "customer per sold currency",
+ )
+ pp_product = fields.Float(
+ string="Points per product",
+ help="Amount of loyalty points given to the " "customer per product sold",
+ )
+ pp_order = fields.Float(
+ string="Points per order",
+ help="Amount of loyalty points given to the "
+ "customer for each point of sale order",
+ )
+ rounding = fields.Float(
+ string="Points Rounding",
+ default=1,
+ help="Loyalty point amounts will be rounded to " "multiples of this value",
+ )
+ rule_ids = fields.One2many(
+ comodel_name="loyalty.rule", inverse_name="loyalty_program_id", string="Rules"
+ )
+ reward_ids = fields.One2many(
+ comodel_name="loyalty.reward",
+ inverse_name="loyalty_program_id",
+ string="Rewards",
+ )
diff --git a/pos_loyalty/models/loyalty_reward.py b/pos_loyalty/models/loyalty_reward.py
index ac3d97ebd5..48ea59ad80 100644
--- a/pos_loyalty/models/loyalty_reward.py
+++ b/pos_loyalty/models/loyalty_reward.py
@@ -3,71 +3,80 @@
# Copyright 2018 Lambda IS DOOEL
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-from odoo import fields, models, api, _
+from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
class LoyaltyReward(models.Model):
- _name = 'loyalty.reward'
+ _name = "loyalty.reward"
- name = fields.Char(string='Reward Name', size=32, index=True,
- required=True)
- type = fields.Selection(selection=[('gift', 'Gift'),
- ('discount', 'Discount'),
- ('resale', 'Resale')],
- string='Type', required=True,
- help='Type of the reward')
- minimum_points = fields.Float(string='Minimum Points',
- help='Minimum amount of points the customer'
- ' must have to qualify for this reward')
- point_cost = fields.Float(string='Point Cost',
- help='Cost of the reward per monetary unit '
- 'discounted')
- discount = fields.Float(help='The discount percentage')
- discount_max = fields.Float(string='Discount limit',
- help='Maximum discounted amount allowed for'
- 'this discount reward')
- loyalty_program_id = fields.Many2one(comodel_name='loyalty.program',
- string='Loyalty Program',
- help='The Loyalty Program this reward'
- ' belongs to')
- gift_product_id = fields.Many2one(comodel_name='product.product',
- domain=[('available_in_pos', '=', True)],
- string='Gift Product',
- help='The product given as a reward')
- discount_product_id = fields.Many2one(comodel_name='product.product',
- domain=[
- ('available_in_pos', '=', True)],
- string='Discount Product',
- help='The product used to apply '
- 'discounts')
- point_product_id = fields.Many2one(comodel_name='product.product',
- domain=[
- ('available_in_pos', '=', True)],
- string='Point Product',
- help='Product that represents a point '
- 'that is sold by the customer')
+ name = fields.Char(string="Reward Name", size=32, index=True, required=True)
+ type = fields.Selection(
+ selection=[("gift", "Gift"), ("discount", "Discount"), ("resale", "Resale")],
+ string="Type",
+ required=True,
+ help="Type of the reward",
+ )
+ minimum_points = fields.Float(
+ string="Minimum Points",
+ help="Minimum amount of points the customer"
+ " must have to qualify for this reward",
+ )
+ point_cost = fields.Float(
+ string="Point Cost", help="Cost of the reward per monetary unit " "discounted"
+ )
+ discount = fields.Float(help="The discount percentage")
+ discount_max = fields.Float(
+ string="Discount limit",
+ help="Maximum discounted amount allowed for" "this discount reward",
+ )
+ loyalty_program_id = fields.Many2one(
+ comodel_name="loyalty.program",
+ string="Loyalty Program",
+ help="The Loyalty Program this reward" " belongs to",
+ )
+ gift_product_id = fields.Many2one(
+ comodel_name="product.product",
+ domain=[("available_in_pos", "=", True)],
+ string="Gift Product",
+ help="The product given as a reward",
+ )
+ discount_product_id = fields.Many2one(
+ comodel_name="product.product",
+ domain=[("available_in_pos", "=", True)],
+ string="Discount Product",
+ help="The product used to apply " "discounts",
+ )
+ point_product_id = fields.Many2one(
+ comodel_name="product.product",
+ domain=[("available_in_pos", "=", True)],
+ string="Point Product",
+ help="Product that represents a point " "that is sold by the customer",
+ )
@api.multi
- @api.constrains('type', 'gift_product_id')
+ @api.constrains("type", "gift_product_id")
def _check_gift_product(self):
for reward in self:
- if reward.type == 'gift' and not reward.gift_product_id:
+ if reward.type == "gift" and not reward.gift_product_id:
raise ValidationError(
- _('Gift product field is mandatory for gift rewards'))
+ _("Gift product field is mandatory for gift rewards")
+ )
@api.multi
- @api.constrains('type', 'discount_product_id')
+ @api.constrains("type", "discount_product_id")
def _check_discount_product(self):
for reward in self:
- if reward.type == 'discount' and not reward.discount_product_id:
- raise ValidationError(_('Discount product field is '
- 'mandatory for discount rewards'))
+ if reward.type == "discount" and not reward.discount_product_id:
+ raise ValidationError(
+ _("Discount product field is " "mandatory for discount rewards")
+ )
@api.multi
- @api.constrains('type', 'point_product_id')
+ @api.constrains("type", "point_product_id")
def _check_point_product(self):
for reward in self:
- if reward.type == 'resale' and not reward.point_product_id:
- raise ValidationError(_('Point product field is '
- 'mandatory for point resale rewards'))
+ if reward.type == "resale" and not reward.point_product_id:
+ raise ValidationError(
+ _("Point product field is " "mandatory for point resale rewards")
+ )
diff --git a/pos_loyalty/models/loyalty_rule.py b/pos_loyalty/models/loyalty_rule.py
index 85caafe65b..329d1da790 100644
--- a/pos_loyalty/models/loyalty_rule.py
+++ b/pos_loyalty/models/loyalty_rule.py
@@ -7,28 +7,40 @@
class LoyaltyRule(models.Model):
- _name = 'loyalty.rule'
+ _name = "loyalty.rule"
- name = fields.Char(string='Rule Name', size=32, index=True, required=True)
- type = fields.Selection(selection=[('product', 'Product'),
- ('category', 'Category')],
- string='Type', required=True, default='product',
- help='The concept this rule applies to')
- cumulative = fields.Boolean(help='The points from this rule will be added '
- 'to points won from other rules with '
- 'the same concept')
- pp_product = fields.Float(string='Points per product',
- help='Amount of points earned per product')
- pp_currency = fields.Float(string='Points per currency',
- help='Amount of points earned per currency')
- loyalty_program_id = fields.Many2one(comodel_name='loyalty.program',
- string='Loyalty Program',
- help='The Loyalty Program this rule '
- 'belongs to')
- product_id = fields.Many2one(comodel_name='product.product',
- domain=[('available_in_pos', '=', True)],
- string='Target Product',
- help='The product affected by this rule')
- category_id = fields.Many2one(comodel_name='pos.category',
- string='Target Category',
- help='The category affected by this rule')
+ name = fields.Char(string="Rule Name", size=32, index=True, required=True)
+ type = fields.Selection(
+ selection=[("product", "Product"), ("category", "Category")],
+ string="Type",
+ required=True,
+ default="product",
+ help="The concept this rule applies to",
+ )
+ cumulative = fields.Boolean(
+ help="The points from this rule will be added "
+ "to points won from other rules with "
+ "the same concept"
+ )
+ pp_product = fields.Float(
+ string="Points per product", help="Amount of points earned per product"
+ )
+ pp_currency = fields.Float(
+ string="Points per currency", help="Amount of points earned per currency"
+ )
+ loyalty_program_id = fields.Many2one(
+ comodel_name="loyalty.program",
+ string="Loyalty Program",
+ help="The Loyalty Program this rule " "belongs to",
+ )
+ product_id = fields.Many2one(
+ comodel_name="product.product",
+ domain=[("available_in_pos", "=", True)],
+ string="Target Product",
+ help="The product affected by this rule",
+ )
+ category_id = fields.Many2one(
+ comodel_name="pos.category",
+ string="Target Category",
+ help="The category affected by this rule",
+ )
diff --git a/pos_loyalty/models/pos_config.py b/pos_loyalty/models/pos_config.py
index b39e549df2..d0fd782aab 100644
--- a/pos_loyalty/models/pos_config.py
+++ b/pos_loyalty/models/pos_config.py
@@ -6,9 +6,10 @@
class PosConfig(models.Model):
- _inherit = 'pos.config'
+ _inherit = "pos.config"
- loyalty_id = fields.Many2one(comodel_name='loyalty.program',
- string='Loyalty Program',
- help='The loyalty program used by this '
- 'Point of Sale')
+ loyalty_id = fields.Many2one(
+ comodel_name="loyalty.program",
+ string="Loyalty Program",
+ help="The loyalty program used by this " "Point of Sale",
+ )
diff --git a/pos_loyalty/models/pos_order.py b/pos_loyalty/models/pos_order.py
index bc6440655a..ae4dca9c61 100644
--- a/pos_loyalty/models/pos_order.py
+++ b/pos_loyalty/models/pos_order.py
@@ -2,29 +2,30 @@
# Copyright 2017 RGB Consulting S.L. (https://www.rgbconsulting.com)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-from odoo import fields, models, api
+from odoo import api, fields, models
class PosOrder(models.Model):
- _inherit = 'pos.order'
+ _inherit = "pos.order"
- loyalty_points = fields.Float(string='Loyalty Points',
- help='The amount of Loyalty points awarded '
- 'to the customer with this order')
+ loyalty_points = fields.Float(
+ string="Loyalty Points",
+ help="The amount of Loyalty points awarded " "to the customer with this order",
+ )
@api.model
def _order_fields(self, ui_order):
res = super(PosOrder, self)._order_fields(ui_order)
- res['loyalty_points'] = ui_order.get('loyalty_points', 0)
+ res["loyalty_points"] = ui_order.get("loyalty_points", 0)
return res
@api.model
def create_from_ui(self, orders):
res = super(PosOrder, self).create_from_ui(orders)
for order in orders:
- order_partner = order['data']['partner_id']
- order_points = order['data'].get('loyalty_points', 0)
+ order_partner = order["data"]["partner_id"]
+ order_points = order["data"].get("loyalty_points", 0)
if order_points != 0 and order_partner:
- partner = self.env['res.partner'].browse(order_partner)
+ partner = self.env["res.partner"].browse(order_partner)
partner.loyalty_points += order_points
return res
diff --git a/pos_loyalty/models/pos_order_line.py b/pos_loyalty/models/pos_order_line.py
index fe9182f53a..e73644a59d 100644
--- a/pos_loyalty/models/pos_order_line.py
+++ b/pos_loyalty/models/pos_order_line.py
@@ -5,16 +5,15 @@
class PosOrderLine(models.Model):
- _inherit = 'pos.order.line'
+ _inherit = "pos.order.line"
@api.model
def _order_line_fields(self, line, session_id=None):
- line = super(PosOrderLine, self)._order_line_fields(
- line, session_id=session_id)
- if line and 'reward_id' in line[2]:
+ line = super(PosOrderLine, self)._order_line_fields(line, session_id=session_id)
+ if line and "reward_id" in line[2]:
# Delete the key since field doesn't exist
# and raises a warning in the logs.
# TODO: add field and remove this if data will be
# used on server, example in report / widget.
- del line[2]['reward_id']
+ del line[2]["reward_id"]
return line
diff --git a/pos_loyalty/models/res_partner.py b/pos_loyalty/models/res_partner.py
index 60350f0494..5af49cb03c 100644
--- a/pos_loyalty/models/res_partner.py
+++ b/pos_loyalty/models/res_partner.py
@@ -6,8 +6,9 @@
class ResPartner(models.Model):
- _inherit = 'res.partner'
+ _inherit = "res.partner"
- loyalty_points = fields.Float(string='Loyalty Points',
- help='The loyalty points the user won as '
- 'part of a Loyalty Program')
+ loyalty_points = fields.Float(
+ string="Loyalty Points",
+ help="The loyalty points the user won as " "part of a Loyalty Program",
+ )
diff --git a/pos_loyalty/static/src/css/pos.css b/pos_loyalty/static/src/css/pos.css
index 4d14191861..a16993f431 100644
--- a/pos_loyalty/static/src/css/pos.css
+++ b/pos_loyalty/static/src/css/pos.css
@@ -1,16 +1,15 @@
-
-.pos .order .summary .loyalty-points{
+.pos .order .summary .loyalty-points {
margin-left: 20px;
float: left;
padding: 10px;
max-width: 216px;
text-align: left;
- color: #6EC89B;
+ color: #6ec89b;
background: rgba(110, 200, 155, 0.17);
border-radius: 3px;
}
-.pos .order .summary .loyalty-points.negative{
- color: #C86E6E;
+.pos .order .summary .loyalty-points.negative {
+ color: #c86e6e;
background: rgba(200, 110, 110, 0.17);
}
.pos .order .summary .loyalty-points-total {
diff --git a/pos_loyalty/static/src/js/pos.js b/pos_loyalty/static/src/js/pos.js
index 91f07f86fc..09c44947b4 100644
--- a/pos_loyalty/static/src/js/pos.js
+++ b/pos_loyalty/static/src/js/pos.js
@@ -2,90 +2,116 @@
* Copyright 2017 RGB Consulting S.L. (https://www.rgbconsulting.com)
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
-odoo.define('pos_loyalty.loyalty_program', function(require) {
- "use strict"
+odoo.define("pos_loyalty.loyalty_program", function(require) {
+ "use strict";
- var models = require('point_of_sale.models');
- var screens = require('point_of_sale.screens');
+ var models = require("point_of_sale.models");
+ var screens = require("point_of_sale.screens");
- var utils = require('web.utils');
+ var utils = require("web.utils");
var round_pr = utils.round_precision;
- var core = require('web.core');
+ var core = require("web.core");
var QWeb = core.qweb;
var _t = core._t;
- models.load_fields('res.partner', 'loyalty_points');
-
- models.load_models([{
- model: 'loyalty.program',
- condition: function(self) {
- return !!self.config.loyalty_id[0];
- },
- fields: ['name', 'pp_currency', 'pp_product', 'pp_order', 'rounding'],
- domain: function(self) {
- return [
- ['id', '=', self.config.loyalty_id[0]]
- ];
- },
- loaded: function(self, loyalties) {
- self.loyalty = loyalties[0];
- },
- }, {
- model: 'loyalty.rule',
- condition: function(self) {
- return !!self.loyalty;
- },
- fields: ['name', 'type', 'product_id', 'category_id', 'cumulative', 'pp_product', 'pp_currency'],
- domain: function(self) {
- return [
- ['loyalty_program_id', '=', self.loyalty.id]
- ];
- },
- loaded: function(self, rules) {
-
- self.loyalty.rules = rules;
- self.loyalty.rules_by_product_id = {};
- self.loyalty.rules_by_category_id = {};
-
- function update_rules(rules, rule, id) {
- if (!rules[id]) {
- rules[id] = [rule];
- } else if (rule.cumulative) {
- rules[id].unshift(rule);
- } else {
- rules[id].push(rule);
- }
- }
+ models.load_fields("res.partner", "loyalty_points");
+
+ models.load_models(
+ [
+ {
+ model: "loyalty.program",
+ condition: function(self) {
+ return Boolean(self.config.loyalty_id[0]);
+ },
+ fields: ["name", "pp_currency", "pp_product", "pp_order", "rounding"],
+ domain: function(self) {
+ return [["id", "=", self.config.loyalty_id[0]]];
+ },
+ loaded: function(self, loyalties) {
+ self.loyalty = loyalties[0];
+ },
+ },
+ {
+ model: "loyalty.rule",
+ condition: function(self) {
+ return Boolean(self.loyalty);
+ },
+ fields: [
+ "name",
+ "type",
+ "product_id",
+ "category_id",
+ "cumulative",
+ "pp_product",
+ "pp_currency",
+ ],
+ domain: function(self) {
+ return [["loyalty_program_id", "=", self.loyalty.id]];
+ },
+ loaded: function(self, rules) {
+ self.loyalty.rules = rules;
+ self.loyalty.rules_by_product_id = {};
+ self.loyalty.rules_by_category_id = {};
+
+ function update_rules(rules, rule, id) {
+ if (!rules[id]) {
+ rules[id] = [rule];
+ } else if (rule.cumulative) {
+ rules[id].unshift(rule);
+ } else {
+ rules[id].push(rule);
+ }
+ }
- _.each(rules, function(rule) {
- if (rule.type === 'product')
- update_rules(self.loyalty.rules_by_product_id, rule, rule.product_id[0])
- else if (rule.type === 'category')
- update_rules(self.loyalty.rules_by_category_id, rule, rule.category_id[0]);
- });
- },
- }, {
- model: 'loyalty.reward',
- condition: function(self) {
- return !!self.loyalty;
- },
- fields: ['name', 'type', 'minimum_points', 'gift_product_id', 'point_cost', 'discount_product_id', 'discount', 'discount_max', 'point_product_id'],
- domain: function(self) {
- return [
- ['loyalty_program_id', '=', self.loyalty.id]
- ];
- },
- loaded: function(self, rewards) {
- self.loyalty.rewards = rewards;
- self.loyalty.rewards_by_id = {};
- for (var i = 0; i < rewards.length; i++) {
- self.loyalty.rewards_by_id[rewards[i].id] = rewards[i];
- }
- },
- }, ], {
- 'after': 'product.product'
- });
+ _.each(rules, function(rule) {
+ if (rule.type === "product")
+ update_rules(
+ self.loyalty.rules_by_product_id,
+ rule,
+ rule.product_id[0]
+ );
+ else if (rule.type === "category")
+ update_rules(
+ self.loyalty.rules_by_category_id,
+ rule,
+ rule.category_id[0]
+ );
+ });
+ },
+ },
+ {
+ model: "loyalty.reward",
+ condition: function(self) {
+ return Boolean(self.loyalty);
+ },
+ fields: [
+ "name",
+ "type",
+ "minimum_points",
+ "gift_product_id",
+ "point_cost",
+ "discount_product_id",
+ "discount",
+ "discount_max",
+ "point_product_id",
+ ],
+ domain: function(self) {
+ return [["loyalty_program_id", "=", self.loyalty.id]];
+ },
+ loaded: function(self, rewards) {
+ self.loyalty.rewards = rewards;
+ self.loyalty.rewards_by_id = {};
+ for (var i = 0; i < rewards.length; i++) {
+ self.loyalty.rewards_by_id[rewards[i].id] = rewards[i];
+ }
+ },
+ },
+ ],
+ {
+ after: "product.product",
+ }
+ );
var _orderline_super = models.Orderline.prototype;
models.Orderline = models.Orderline.extend({
@@ -108,7 +134,6 @@ odoo.define('pos_loyalty.loyalty_program', function(require) {
var _order_super = models.Order.prototype;
models.Order = models.Order.extend({
-
/* The total of points won, excluding the points spent on rewards */
get_won_points: function() {
if (!this.pos.loyalty || !this.get_client()) {
@@ -128,15 +153,22 @@ odoo.define('pos_loyalty.loyalty_program', function(require) {
var rules = this.pos.loyalty.rules_by_product_id[product.id] || [];
var overriden = false;
- if (line.get_reward()) { // Reward products are ignored
+ if (line.get_reward()) {
+ // Reward products are ignored
continue;
}
for (var j = 0; j < rules.length; j++) {
var rule = rules[j];
- total_points += round_pr(line.get_quantity() * rule.pp_product, rounding);
- total_points += round_pr(line.get_price_with_tax() * rule.pp_currency, rounding);
- // if affected by a non cumulative rule, skip the others. (non cumulative rules are put
+ total_points += round_pr(
+ line.get_quantity() * rule.pp_product,
+ rounding
+ );
+ total_points += round_pr(
+ line.get_price_with_tax() * rule.pp_currency,
+ rounding
+ );
+ // If affected by a non cumulative rule, skip the others. (non cumulative rules are put
// at the beginning of the list when they are loaded )
if (!rule.cumulative) {
overriden = true;
@@ -146,20 +178,31 @@ odoo.define('pos_loyalty.loyalty_program', function(require) {
// Test the category rules
if (product.pos_categ_id) {
- var category = this.pos.db.get_category_by_id(product.pos_categ_id[0]);
+ var category = this.pos.db.get_category_by_id(
+ product.pos_categ_id[0]
+ );
while (category && !overriden) {
- var rules = this.pos.loyalty.rules_by_category_id[category.id] || [];
+ var rules =
+ this.pos.loyalty.rules_by_category_id[category.id] || [];
for (var j = 0; j < rules.length; j++) {
var rule = rules[j];
- total_points += round_pr(line.get_quantity() * rule.pp_product, rounding);
- total_points += round_pr(line.get_price_with_tax() * rule.pp_currency, rounding);
+ total_points += round_pr(
+ line.get_quantity() * rule.pp_product,
+ rounding
+ );
+ total_points += round_pr(
+ line.get_price_with_tax() * rule.pp_currency,
+ rounding
+ );
if (!rule.cumulative) {
overriden = true;
break;
}
}
var _category = category;
- category = this.pos.db.get_category_by_id(this.pos.db.get_category_parent_id(category.id));
+ category = this.pos.db.get_category_by_id(
+ this.pos.db.get_category_parent_id(category.id)
+ );
if (_category === category) {
break;
}
@@ -172,8 +215,14 @@ odoo.define('pos_loyalty.loyalty_program', function(require) {
}
}
- total_points += round_pr(total_sold * this.pos.loyalty.pp_currency, rounding);
- total_points += round_pr(product_sold * this.pos.loyalty.pp_product, rounding);
+ total_points += round_pr(
+ total_sold * this.pos.loyalty.pp_currency,
+ rounding
+ );
+ total_points += round_pr(
+ product_sold * this.pos.loyalty.pp_product,
+ rounding
+ );
total_points += round_pr(this.pos.loyalty.pp_order, rounding);
return total_points;
@@ -183,45 +232,51 @@ odoo.define('pos_loyalty.loyalty_program', function(require) {
get_spent_points: function() {
if (!this.pos.loyalty || !this.get_client()) {
return 0;
- } else {
- var lines = this.get_orderlines();
- var rounding = this.pos.loyalty.rounding;
- var points = 0;
-
- for (var i = 0; i < lines.length; i++) {
- var line = lines[i];
- var reward = line.get_reward();
- if (reward) {
- if (reward.type === 'gift') {
- points += round_pr(line.get_quantity() * reward.point_cost, rounding);
- } else if (reward.type === 'discount') {
- points += reward.point_cost;
- } else if (reward.type === 'resale') {
- points += (-line.get_quantity());
- }
+ }
+ var lines = this.get_orderlines();
+ var rounding = this.pos.loyalty.rounding;
+ var points = 0;
+
+ for (var i = 0; i < lines.length; i++) {
+ var line = lines[i];
+ var reward = line.get_reward();
+ if (reward) {
+ if (reward.type === "gift") {
+ points += round_pr(
+ line.get_quantity() * reward.point_cost,
+ rounding
+ );
+ } else if (reward.type === "discount") {
+ points += reward.point_cost;
+ } else if (reward.type === "resale") {
+ points += -line.get_quantity();
}
}
-
- return points;
}
+
+ return points;
},
/* The total number of points lost or won after the order is validated */
get_new_points: function() {
if (!this.pos.loyalty || !this.get_client()) {
return 0;
- } else {
- return round_pr(this.get_won_points() - this.get_spent_points(), this.pos.loyalty.rounding);
}
+ return round_pr(
+ this.get_won_points() - this.get_spent_points(),
+ this.pos.loyalty.rounding
+ );
},
/* The total number of points that the customer will have after this order is validated */
get_new_total_points: function() {
if (!this.pos.loyalty || !this.get_client()) {
return 0;
- } else {
- return round_pr(this.get_client().loyalty_points + this.get_new_points(), this.pos.loyalty.rounding);
}
+ return round_pr(
+ this.get_client().loyalty_points + this.get_new_points(),
+ this.pos.loyalty.rounding
+ );
},
/* The number of loyalty points currently owned by the customer */
@@ -233,9 +288,11 @@ odoo.define('pos_loyalty.loyalty_program', function(require) {
get_spendable_points: function() {
if (!this.pos.loyalty || !this.get_client()) {
return 0;
- } else {
- return round_pr(this.get_client().loyalty_points - this.get_spent_points(), this.pos.loyalty.rounding);
}
+ return round_pr(
+ this.get_client().loyalty_points - this.get_spent_points(),
+ this.pos.loyalty.rounding
+ );
},
has_discount_reward: function() {
@@ -245,7 +302,7 @@ odoo.define('pos_loyalty.loyalty_program', function(require) {
for (var i = 0; i < lines.length; i++) {
var line = lines[i];
var reward = line.get_reward();
- if (reward && reward.type === 'discount') {
+ if (reward && reward.type === "discount") {
res = true;
break;
}
@@ -266,11 +323,16 @@ odoo.define('pos_loyalty.loyalty_program', function(require) {
if (reward.minimum_points > this.get_spendable_points()) {
continue;
- } else if (reward.type === 'gift' &&
- reward.point_cost > this.get_spendable_points()) {
+ } else if (
+ reward.type === "gift" &&
+ reward.point_cost > this.get_spendable_points()
+ ) {
continue;
- } else if (reward.type === 'discount' &&
- (discount_reward_set || reward.point_cost > this.get_spendable_points())) {
+ } else if (
+ reward.type === "discount" &&
+ (discount_reward_set ||
+ reward.point_cost > this.get_spendable_points())
+ ) {
continue;
}
rewards.push(reward);
@@ -282,7 +344,7 @@ odoo.define('pos_loyalty.loyalty_program', function(require) {
var client = this.get_client();
if (!client) {
return;
- } else if (reward.type === 'gift') {
+ } else if (reward.type === "gift") {
var product = this.pos.db.get_product_by_id(reward.gift_product_id[0]);
if (!product) {
@@ -294,22 +356,22 @@ odoo.define('pos_loyalty.loyalty_program', function(require) {
quantity: 1,
merge: false,
extras: {
- reward_id: reward.id
+ reward_id: reward.id,
},
});
-
- } else if (reward.type === 'discount') {
-
+ } else if (reward.type === "discount") {
var crounding = this.pos.currency.rounding;
var order_total = this.get_total_with_tax();
var discount = round_pr(order_total * reward.discount, crounding);
- var discount_max = reward.discount_max
+ var discount_max = reward.discount_max;
if (discount_max && discount > discount_max) {
discount = discount_max;
}
- var product = this.pos.db.get_product_by_id(reward.discount_product_id[0]);
+ var product = this.pos.db.get_product_by_id(
+ reward.discount_product_id[0]
+ );
if (!product) {
return;
@@ -320,12 +382,10 @@ odoo.define('pos_loyalty.loyalty_program', function(require) {
quantity: 1,
merge: false,
extras: {
- reward_id: reward.id
+ reward_id: reward.id,
},
});
-
- } else if (reward.type === 'resale') {
-
+ } else if (reward.type === "resale") {
var lrounding = this.pos.loyalty.rounding;
var crounding = this.pos.currency.rounding;
var spendable = this.get_spendable_points();
@@ -338,7 +398,10 @@ odoo.define('pos_loyalty.loyalty_program', function(require) {
}
if (round_pr(spendable * product.price, crounding) > order_total) {
- spendable = round_pr(Math.floor(order_total / product.price), lrounding);
+ spendable = round_pr(
+ Math.floor(order_total / product.price),
+ lrounding
+ );
}
if (spendable < 0.00001) {
@@ -349,7 +412,7 @@ odoo.define('pos_loyalty.loyalty_program', function(require) {
quantity: -spendable,
merge: false,
extras: {
- reward_id: reward.id
+ reward_id: reward.id,
},
});
}
@@ -359,7 +422,9 @@ odoo.define('pos_loyalty.loyalty_program', function(require) {
var client = this.get_client();
if (client) {
client.loyalty_points = this.get_new_total_points();
- this.pos.gui.screen_instances.clientlist.partner_cache.clear_node(client.id);
+ this.pos.gui.screen_instances.clientlist.partner_cache.clear_node(
+ client.id
+ );
}
_order_super.finalize.apply(this, arguments);
},
@@ -387,21 +452,23 @@ odoo.define('pos_loyalty.loyalty_program', function(require) {
});
var LoyaltyButton = screens.ActionButtonWidget.extend({
- template: 'LoyaltyButton',
+ template: "LoyaltyButton",
button_click: function() {
var self = this;
var order = this.pos.get_order();
var client = order.get_client();
if (!client) {
- this.gui.show_screen('clientlist');
+ this.gui.show_screen("clientlist");
return;
}
var rewards = order.get_available_rewards();
if (rewards.length === 0) {
- this.gui.show_popup('error', {
- 'title': _t('No Rewards Available'),
- 'body': _t('There are no rewards available for this customer as part of the loyalty program'),
+ this.gui.show_popup("error", {
+ title: _t("No Rewards Available"),
+ body: _t(
+ "There are no rewards available for this customer as part of the loyalty program"
+ ),
});
} else if (rewards.length === 1 && this.pos.loyalty.rewards.length === 1) {
order.apply_reward(rewards[0]);
@@ -413,10 +480,10 @@ odoo.define('pos_loyalty.loyalty_program', function(require) {
item: rewards[i],
});
}
- this.gui.show_popup('selection', {
- 'title': _t('Please select a reward'),
- 'list': list,
- 'confirm': function(reward) {
+ this.gui.show_popup("selection", {
+ title: _t("Please select a reward"),
+ list: list,
+ confirm: function(reward) {
order.apply_reward(reward);
},
});
@@ -425,9 +492,9 @@ odoo.define('pos_loyalty.loyalty_program', function(require) {
});
screens.define_action_button({
- 'name': 'loyalty',
- 'widget': LoyaltyButton,
- 'condition': function() {
+ name: "loyalty",
+ widget: LoyaltyButton,
+ condition: function() {
return this.pos.loyalty && this.pos.loyalty.rewards.length;
},
});
@@ -438,40 +505,47 @@ odoo.define('pos_loyalty.loyalty_program', function(require) {
var order = this.pos.get_order();
- var $loypoints = $(this.el).find('.summary .loyalty-points');
+ var $loypoints = $(this.el).find(".summary .loyalty-points");
if (this.pos.loyalty && order.get_client()) {
var points_won = order.get_won_points();
var points_spent = order.get_spent_points();
var points_total = order.get_new_total_points();
- $loypoints.replaceWith($(QWeb.render('LoyaltyPoints', {
- widget: this,
- rounding: this.pos.loyalty.rounding,
- points_won: points_won,
- points_spent: points_spent,
- points_total: points_total,
- })));
- $loypoints = $(this.el).find('.summary .loyalty-points');
- $loypoints.removeClass('oe_hidden');
+ $loypoints.replaceWith(
+ $(
+ QWeb.render("LoyaltyPoints", {
+ widget: this,
+ rounding: this.pos.loyalty.rounding,
+ points_won: points_won,
+ points_spent: points_spent,
+ points_total: points_total,
+ })
+ )
+ );
+ $loypoints = $(this.el).find(".summary .loyalty-points");
+ $loypoints.removeClass("oe_hidden");
if (points_total < 0) {
- $loypoints.addClass('negative');
+ $loypoints.addClass("negative");
} else {
- $loypoints.removeClass('negative');
+ $loypoints.removeClass("negative");
}
} else {
$loypoints.empty();
- $loypoints.addClass('oe_hidden');
+ $loypoints.addClass("oe_hidden");
}
- if (this.pos.loyalty &&
+ if (
+ this.pos.loyalty &&
order.get_client() &&
this.getParent().action_buttons &&
- this.getParent().action_buttons.loyalty) {
-
+ this.getParent().action_buttons.loyalty
+ ) {
var rewards = order.get_available_rewards();
- this.getParent().action_buttons.loyalty.highlight(!!rewards.length);
+ this.getParent().action_buttons.loyalty.highlight(
+ Boolean(rewards.length)
+ );
}
},
});
-});
\ No newline at end of file
+});
diff --git a/pos_loyalty/static/src/js/tests.js b/pos_loyalty/static/src/js/tests.js
index eff9f48188..492930f994 100644
--- a/pos_loyalty/static/src/js/tests.js
+++ b/pos_loyalty/static/src/js/tests.js
@@ -2,7 +2,7 @@
// Copyright 2018 Lambda IS DOOEL
// License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-odoo.define('pos_loyalty.tour.test_pos_loyalty', function(require) {
+odoo.define("pos_loyalty.tour.test_pos_loyalty", function(require) {
"use strict";
// Some of the steps are taken from the pos_basic_order tour in point_of_sale.
@@ -11,59 +11,80 @@ odoo.define('pos_loyalty.tour.test_pos_loyalty', function(require) {
var Tour = require("web_tour.tour");
function add_customer(customer_name) {
- return [{
- content: 'open customer screen',
- trigger: '.button.set-customer',
- }, {
- content: 'choose customer ' + customer_name,
- trigger: 'table.client-list tbody.client-list-contents tr.client-line td:contains("' + customer_name + '")',
- }, {
- content: 'select customer ' + customer_name,
- trigger: '.button.next:contains("Set Customer")',
- }, {
- content: 'Check if customer ' + customer_name + ' is added',
- trigger: '.button.set-customer:contains("' + customer_name + '")',
- run: function() {}, // it's a check
- }];
+ return [
+ {
+ content: "open customer screen",
+ trigger: ".button.set-customer",
+ },
+ {
+ content: "choose customer " + customer_name,
+ trigger:
+ 'table.client-list tbody.client-list-contents tr.client-line td:contains("' +
+ customer_name +
+ '")',
+ },
+ {
+ content: "select customer " + customer_name,
+ trigger: '.button.next:contains("Set Customer")',
+ },
+ {
+ content: "Check if customer " + customer_name + " is added",
+ trigger: '.button.set-customer:contains("' + customer_name + '")',
+ run: function() {}, // It's a check
+ },
+ ];
}
function add_reward(reward_name) {
- return [{
- content: 'open rewards screen',
- trigger: '.control-button:contains("Rewards")',
- }, {
- content: 'choose reward',
- trigger: '.selection-item:contains("' + reward_name + '")',
- }]
+ return [
+ {
+ content: "open rewards screen",
+ trigger: '.control-button:contains("Rewards")',
+ },
+ {
+ content: "choose reward",
+ trigger: '.selection-item:contains("' + reward_name + '")',
+ },
+ ];
}
function add_product_to_order(product_name) {
- return [{
- content: 'buy ' + product_name,
- trigger: '.product-list .product-name:contains("' + product_name + '")',
- }, {
- content: 'the ' + product_name + ' have been added to the order',
- trigger: '.order .product-name:contains("' + product_name + '")',
- run: function() {}, // it's a check
- }];
+ return [
+ {
+ content: "buy " + product_name,
+ trigger: '.product-list .product-name:contains("' + product_name + '")',
+ },
+ {
+ content: "the " + product_name + " have been added to the order",
+ trigger: '.order .product-name:contains("' + product_name + '")',
+ run: function() {}, // It's a check
+ },
+ ];
}
function verify_order_product(product_name) {
- return [{
- content: 'check if ' + product_name + ' is in order',
- trigger: '.orderline .product-name:contains("' + product_name + '")',
- run: function() {}, // it's a check
- }]
+ return [
+ {
+ content: "check if " + product_name + " is in order",
+ trigger: '.orderline .product-name:contains("' + product_name + '")',
+ run: function() {}, // It's a check
+ },
+ ];
}
function generate_keypad_steps(amount_str, keypad_selector) {
- var i, steps = [],
+ var i,
+ steps = [],
current_char;
for (i = 0; i < amount_str.length; ++i) {
current_char = amount_str[i];
steps.push({
- content: 'press ' + current_char + ' on payment keypad',
- trigger: keypad_selector + ' .input-button:contains("' + current_char + '"):visible'
+ content: "press " + current_char + " on payment keypad",
+ trigger:
+ keypad_selector +
+ ' .input-button:contains("' +
+ current_char +
+ '"):visible',
});
}
@@ -71,100 +92,128 @@ odoo.define('pos_loyalty.tour.test_pos_loyalty', function(require) {
}
function generate_payment_screen_keypad_steps(amount_str) {
- return generate_keypad_steps(amount_str, '.payment-numpad');
+ return generate_keypad_steps(amount_str, ".payment-numpad");
}
function generate_product_screen_keypad_steps(amount_str) {
- return generate_keypad_steps(amount_str, '.numpad');
+ return generate_keypad_steps(amount_str, ".numpad");
}
function verify_order_total(total_str) {
- return [{
- content: 'order total contains ' + total_str,
- trigger: '.order .total .value:contains("' + total_str + '")',
- run: function() {}, // it's a check
- }];
+ return [
+ {
+ content: "order total contains " + total_str,
+ trigger: '.order .total .value:contains("' + total_str + '")',
+ run: function() {}, // It's a check
+ },
+ ];
}
function goto_payment_screen_and_select_payment_method() {
- return [{
- content: "go to payment screen",
- trigger: '.button.pay',
- }, {
- content: "pay with cash",
- trigger: '.paymentmethod:contains("Cash")',
- }];
+ return [
+ {
+ content: "go to payment screen",
+ trigger: ".button.pay",
+ },
+ {
+ content: "pay with cash",
+ trigger: '.paymentmethod:contains("Cash")',
+ },
+ ];
}
function finish_order() {
- return [{
- content: "validate the order",
- trigger: '.button.next:visible',
- }, {
- content: "verify that the order is being sent to the backend",
- trigger: ".js_connecting:visible",
- run: function() {}, // it's a check
- }, {
- content: "verify that the order has been succesfully sent to the backend",
- trigger: ".js_connected:visible",
- run: function() {}, // it's a check
- }, {
- content: "next order",
- trigger: '.button.next:visible',
- }];
+ return [
+ {
+ content: "validate the order",
+ trigger: ".button.next:visible",
+ },
+ {
+ content: "verify that the order is being sent to the backend",
+ trigger: ".js_connecting:visible",
+ run: function() {}, // It's a check
+ },
+ {
+ content:
+ "verify that the order has been succesfully sent to the backend",
+ trigger: ".js_connected:visible",
+ run: function() {}, // It's a check
+ },
+ {
+ content: "next order",
+ trigger: ".button.next:visible",
+ },
+ ];
}
- var steps = [{
- content: 'waiting for loading to finish',
- trigger: '.o_main_content:has(.loader:hidden)',
- run: function() {}, // it's a check
- }];
+ var steps = [
+ {
+ content: "waiting for loading to finish",
+ trigger: ".o_main_content:has(.loader:hidden)",
+ run: function() {}, // It's a check
+ },
+ ];
- steps = steps.concat(add_customer('Agrolait'));
- steps = steps.concat(add_product_to_order('Peaches'));
- steps = steps.concat(verify_order_total('5.10'));
+ steps = steps.concat(add_customer("Agrolait"));
+ steps = steps.concat(add_product_to_order("Peaches"));
+ steps = steps.concat(verify_order_total("5.10"));
- steps = steps.concat(add_product_to_order('Peaches')); // buy another kg of peaches
- steps = steps.concat(verify_order_total('10.20'));
+ steps = steps.concat(add_product_to_order("Peaches")); // Buy another kg of peaches
+ steps = steps.concat(verify_order_total("10.20"));
steps = steps.concat(goto_payment_screen_and_select_payment_method());
steps = steps.concat(generate_payment_screen_keypad_steps("12.20"));
- steps = steps.concat([{
- content: "verify tendered",
- trigger: '.col-tendered:contains("12.20")',
- run: function() {}, // it's a check
- }, {
- content: "verify change",
- trigger: '.col-change:contains("2.00")',
- run: function() {}, // it's a check
- }]);
+ steps = steps.concat([
+ {
+ content: "verify tendered",
+ trigger: '.col-tendered:contains("12.20")',
+ run: function() {}, // It's a check
+ },
+ {
+ content: "verify change",
+ trigger: '.col-change:contains("2.00")',
+ run: function() {}, // It's a check
+ },
+ ]);
steps = steps.concat(finish_order());
- Tour.register('test_pos_loyalty_acquire_points', {
- test: true,
- url: '/pos/web'
- }, steps);
-
- steps = [{
- content: 'waiting for loading to finish',
- trigger: '.o_main_content:has(.loader:hidden)',
- run: function() {}, // it's a check
- }];
- steps = steps.concat(add_customer('Agrolait'));
- steps = steps.concat(add_reward('Free Peaches'));
- steps = steps.concat(verify_order_product('Peaches'));
- steps = steps.concat(verify_order_total('0.00'));
+ Tour.register(
+ "test_pos_loyalty_acquire_points",
+ {
+ test: true,
+ url: "/pos/web",
+ },
+ steps
+ );
+
+ steps = [
+ {
+ content: "waiting for loading to finish",
+ trigger: ".o_main_content:has(.loader:hidden)",
+ run: function() {}, // It's a check
+ },
+ ];
+ steps = steps.concat(add_customer("Agrolait"));
+ steps = steps.concat(add_reward("Free Peaches"));
+ steps = steps.concat(verify_order_product("Peaches"));
+ steps = steps.concat(verify_order_total("0.00"));
steps = steps.concat(goto_payment_screen_and_select_payment_method());
- steps = steps.concat([{
- content: "verify tendered",
- trigger: '.col-tendered:contains("0.00")',
- run: function() {}, // it's a check
- }]);
+ steps = steps.concat([
+ {
+ content: "verify tendered",
+ trigger: '.col-tendered:contains("0.00")',
+ run: function() {}, // It's a check
+ },
+ ]);
steps = steps.concat(finish_order());
- Tour.register('test_pos_loyalty_spend_points', {
- test: true,
- url: '/pos/web'
- }, steps);
-})
\ No newline at end of file
+ Tour.register(
+ "test_pos_loyalty_spend_points",
+ {
+ test: true,
+ url: "/pos/web",
+ },
+ steps
+ );
+});
diff --git a/pos_loyalty/static/src/xml/pos.xml b/pos_loyalty/static/src/xml/pos.xml
index 988096db61..5df8e5b5d6 100644
--- a/pos_loyalty/static/src/xml/pos.xml
+++ b/pos_loyalty/static/src/xml/pos.xml
@@ -1,85 +1,112 @@
-
+
-
Points
- +
+ +
- -
+ -
-
+
+
+
-
Rewards
-
.
-
-
+
|
-
--------------------------------
-
-
-
-
+
+
+
+
+
+
+
+
- Points Won
+
+ Points Won
+
+
+
+
+
+
- Points Spent
+
+ Points Spent
+
+
+
+
+
+
- Total Points
+
+ Total Points
+
+
+
+
+
+
-
Points
-
+
-
Points |
-
diff --git a/pos_loyalty/tests/__init__.py b/pos_loyalty/tests/__init__.py
index 09e18a0136..9f83594a5c 100644
--- a/pos_loyalty/tests/__init__.py
+++ b/pos_loyalty/tests/__init__.py
@@ -1,2 +1 @@
-
from . import test_pos_loyalty
diff --git a/pos_loyalty/tests/test_pos_loyalty.py b/pos_loyalty/tests/test_pos_loyalty.py
index 0cd3ef383d..0c63cab96a 100644
--- a/pos_loyalty/tests/test_pos_loyalty.py
+++ b/pos_loyalty/tests/test_pos_loyalty.py
@@ -6,63 +6,85 @@
class TestPOSLoyalty(HttpCase):
-
def test_pos_loyalty(self):
- main_pos_config = self.env.ref('point_of_sale.pos_config_main')
- target_product = self.env.ref('point_of_sale.letter_tray')
- free_product = self.env.ref('point_of_sale.desk_organizer')
- customer = self.env.ref('base.res_partner_2')
- loyalty_program = self.env['loyalty.program'].create({
- 'name': 'foo',
- 'rule_ids': [(0, 0, {
- 'name': 'Peaches',
- 'type': 'product',
- 'product_id': target_product.id,
- 'pp_product': 10,
- })],
- 'reward_ids': [(0, 0, {
- 'name': 'Free Peaches',
- 'type': 'gift',
- 'gift_product_id': target_product.id,
- 'point_cost': 20,
- 'minimum_points': 20,
- }), (0, 0, {
- 'name': 'Free Onions',
- 'type': 'gift',
- 'gift_product_id': free_product.id,
- 'point_cost': 20,
- 'minimum_points': 20,
- })]
- })
- main_pos_config.write({'loyalty_id': loyalty_program.id})
+ main_pos_config = self.env.ref("point_of_sale.pos_config_main")
+ target_product = self.env.ref("point_of_sale.letter_tray")
+ free_product = self.env.ref("point_of_sale.desk_organizer")
+ customer = self.env.ref("base.res_partner_2")
+ loyalty_program = self.env["loyalty.program"].create(
+ {
+ "name": "foo",
+ "rule_ids": [
+ (
+ 0,
+ 0,
+ {
+ "name": "Peaches",
+ "type": "product",
+ "product_id": target_product.id,
+ "pp_product": 10,
+ },
+ )
+ ],
+ "reward_ids": [
+ (
+ 0,
+ 0,
+ {
+ "name": "Free Peaches",
+ "type": "gift",
+ "gift_product_id": target_product.id,
+ "point_cost": 20,
+ "minimum_points": 20,
+ },
+ ),
+ (
+ 0,
+ 0,
+ {
+ "name": "Free Onions",
+ "type": "gift",
+ "gift_product_id": free_product.id,
+ "point_cost": 20,
+ "minimum_points": 20,
+ },
+ ),
+ ],
+ }
+ )
+ main_pos_config.write({"loyalty_id": loyalty_program.id})
main_pos_config.open_session_cb()
# needed because tests are run before the module is marked as
# installed. In js web will only load qweb coming from modules
# that are returned by the backend in module_boot. Without
# this you end up with js, css but no qweb.
- self.env['ir.module.module'].search(
- [('name', '=', 'pos_loyalty')], limit=1).state = 'installed'
+ self.env["ir.module.module"].search(
+ [("name", "=", "pos_loyalty")], limit=1
+ ).state = "installed"
# Process an order with 2kg of Peaches which should
# add 20 loyalty points
- self.phantom_js("/pos/web",
- "odoo.__DEBUG__.services['web_tour.tour'].run("
- "'test_pos_loyalty_acquire_points')",
- "odoo.__DEBUG__.services['web_tour.tour'].tours"
- ".test_pos_loyalty_acquire_points.ready",
- login="admin")
+ self.phantom_js(
+ "/pos/web",
+ "odoo.__DEBUG__.services['web_tour.tour'].run("
+ "'test_pos_loyalty_acquire_points')",
+ "odoo.__DEBUG__.services['web_tour.tour'].tours"
+ ".test_pos_loyalty_acquire_points.ready",
+ login="admin",
+ )
self.assertEqual(customer.loyalty_points, 20)
# Spend 20 loyalty points on "Free Peaches" reward
- self.phantom_js("/pos/web",
- "odoo.__DEBUG__.services['web_tour.tour'].run("
- "'test_pos_loyalty_spend_points')",
- "odoo.__DEBUG__.services['web_tour.tour'].tours"
- ".test_pos_loyalty_spend_points.ready",
- login="admin")
+ self.phantom_js(
+ "/pos/web",
+ "odoo.__DEBUG__.services['web_tour.tour'].run("
+ "'test_pos_loyalty_spend_points')",
+ "odoo.__DEBUG__.services['web_tour.tour'].tours"
+ ".test_pos_loyalty_spend_points.ready",
+ login="admin",
+ )
- customer_points = customer.read(
- ['loyalty_points'])[0]['loyalty_points']
+ customer_points = customer.read(["loyalty_points"])[0]["loyalty_points"]
self.assertEqual(customer_points, 0)
diff --git a/pos_loyalty/views/loyalty_program_view.xml b/pos_loyalty/views/loyalty_program_view.xml
index 65f3d24724..447557756d 100644
--- a/pos_loyalty/views/loyalty_program_view.xml
+++ b/pos_loyalty/views/loyalty_program_view.xml
@@ -1,4 +1,4 @@
-
+
loyalty.program.form
@@ -7,57 +7,54 @@
-
loyalty.program.tree
loyalty.program
-
+
-
Loyalty Programs
ir.actions.act_window
@@ -74,10 +71,11 @@
-
-
+
diff --git a/pos_loyalty/views/loyalty_reward_view.xml b/pos_loyalty/views/loyalty_reward_view.xml
index f194ccaca3..dad44b4bbd 100644
--- a/pos_loyalty/views/loyalty_reward_view.xml
+++ b/pos_loyalty/views/loyalty_reward_view.xml
@@ -1,4 +1,4 @@
-
+
loyalty.reward.form
@@ -6,30 +6,42 @@
diff --git a/pos_loyalty/views/loyalty_rule_view.xml b/pos_loyalty/views/loyalty_rule_view.xml
index bf1152d987..50186817cf 100644
--- a/pos_loyalty/views/loyalty_rule_view.xml
+++ b/pos_loyalty/views/loyalty_rule_view.xml
@@ -1,4 +1,4 @@
-
+
loyalty.rule.form
@@ -6,24 +6,30 @@
diff --git a/pos_loyalty/views/pos_config_view.xml b/pos_loyalty/views/pos_config_view.xml
index 8988a0562a..b66797b19d 100644
--- a/pos_loyalty/views/pos_config_view.xml
+++ b/pos_loyalty/views/pos_config_view.xml
@@ -1,19 +1,19 @@
-
+
pos.config.form
pos.config
-
+
-
+
Loyalty program that will be available in this PoS
-
+
diff --git a/pos_loyalty/views/pos_order_view.xml b/pos_loyalty/views/pos_order_view.xml
index 225f610a54..e00e6ed7d9 100644
--- a/pos_loyalty/views/pos_order_view.xml
+++ b/pos_loyalty/views/pos_order_view.xml
@@ -1,13 +1,13 @@
-
+
pos.order.form
pos.order
-
+
-
+
diff --git a/pos_loyalty/views/res_partner_view.xml b/pos_loyalty/views/res_partner_view.xml
index c183f50d29..e1f025d66a 100644
--- a/pos_loyalty/views/res_partner_view.xml
+++ b/pos_loyalty/views/res_partner_view.xml
@@ -1,16 +1,20 @@
-
+
partner.property.form
res.partner
-
+
diff --git a/pos_loyalty/views/templates.xml b/pos_loyalty/views/templates.xml
index d05d64a818..53264a9dc5 100644
--- a/pos_loyalty/views/templates.xml
+++ b/pos_loyalty/views/templates.xml
@@ -1,9 +1,9 @@
-
+
-
-
+
+
diff --git a/setup/pos_loyalty/odoo/addons/pos_loyalty b/setup/pos_loyalty/odoo/addons/pos_loyalty
new file mode 120000
index 0000000000..806cfeccea
--- /dev/null
+++ b/setup/pos_loyalty/odoo/addons/pos_loyalty
@@ -0,0 +1 @@
+../../../../pos_loyalty
\ No newline at end of file
diff --git a/setup/pos_loyalty/setup.py b/setup/pos_loyalty/setup.py
new file mode 100644
index 0000000000..28c57bb640
--- /dev/null
+++ b/setup/pos_loyalty/setup.py
@@ -0,0 +1,6 @@
+import setuptools
+
+setuptools.setup(
+ setup_requires=['setuptools-odoo'],
+ odoo_addon=True,
+)