Skip to content

Commit

Permalink
[IMP] black, isort, prettier.
Browse files Browse the repository at this point in the history
  • Loading branch information
dsolanki-initos committed Apr 16, 2021
1 parent a3b4e19 commit e023a00
Show file tree
Hide file tree
Showing 24 changed files with 784 additions and 561 deletions.
50 changes: 22 additions & 28 deletions pos_loyalty/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
4 changes: 2 additions & 2 deletions pos_loyalty/demo/templates.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<template id="assets_demo" inherit_id="point_of_sale.assets">
<xpath expr="." position="inside">
<script type="text/javascript" src="/pos_loyalty/static/src/js/tests.js"></script>
<script type="text/javascript" src="/pos_loyalty/static/src/js/tests.js" />
</xpath>
</template>
</odoo>
51 changes: 30 additions & 21 deletions pos_loyalty/models/loyalty_program.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
109 changes: 59 additions & 50 deletions pos_loyalty/models/loyalty_reward.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,80 @@
# Copyright 2018 Lambda IS DOOEL <https://www.lambda-is.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
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")
)
60 changes: 36 additions & 24 deletions pos_loyalty/models/loyalty_rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
11 changes: 6 additions & 5 deletions pos_loyalty/models/pos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
19 changes: 10 additions & 9 deletions pos_loyalty/models/pos_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
9 changes: 4 additions & 5 deletions pos_loyalty/models/pos_order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Loading

0 comments on commit e023a00

Please sign in to comment.