[REM] pos_gift_card: remove pos_gift_card module

Removes the pos_gift_card module as it is merged inside of pos_loyalty.

TaskId-2675382
This commit is contained in:
William Braeckman
2022-04-08 09:38:45 +02:00
parent 3cb1448133
commit 29888f1cd9
22 changed files with 0 additions and 1178 deletions
-4
View File
@@ -1,4 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import models
-32
View File
@@ -1,32 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
{
'name': "Gift Card for point of sales module",
'summary': "Use gift card in your sales orders",
'description': """Integrate gift card mechanism in sales orders.""",
'category': 'Sales/Sales',
'version': '1.0',
'depends': ['gift_card', 'point_of_sale'],
'auto_install': True,
'data': [
'data/gift_card_data.xml',
'views/gift_card_views.xml',
'views/res_config_settings_views.xml',
'views/pos_config_views.xml',
'security/ir.model.access.csv',
],
'assets': {
'point_of_sale.assets': [
'pos_gift_card/static/src/css/giftCard.css',
'pos_gift_card/static/src/js/models.js',
'pos_gift_card/static/src/js/GiftCardButton.js',
'pos_gift_card/static/src/js/GiftCardPopup.js',
'pos_gift_card/static/src/js/PaymentScreen.js',
],
'web.assets_qweb': [
'pos_gift_card/static/src/xml/**/*',
],
},
'license': 'LGPL-3',
}
@@ -1,54 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data noupdate="1">
<!-- the product used to deduce on sale order -->
<record id="gift_card.pay_with_gift_card_product" model="product.product">
<field name="available_in_pos">True</field>
</record>
<record id="gift_card_report_pdf" model="ir.actions.report">
<field name="name">Gift Card</field>
<field name="model">gift.card</field>
<field name="report_type">qweb-pdf</field>
<field name="report_name">pos_gift_card.gift_card_template</field>
<field name="binding_type">report</field>
<field name="binding_model_id" ref="model_gift_card"/>
</record>
<template id="gift_card_template">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="web.external_layout">
<div style="margin:0px; font-size:24px; font-family:arial, 'helvetica neue', helvetica, sans-serif; line-height:36px; color:#333333; text-align: center">
Here is your gift card!
</div>
<div style="padding-top:20px; padding-bottom:20px">
<img src="/gift_card/static/img/gift_card.png" style="display:block; border:0; outline:none; text-decoration:none; margin:auto;" width="300"/>
</div>
<div style="padding:0; margin:0px; padding-top:35px; padding-bottom:35px; text-align:center;">
<h3 style="margin:0px; line-height:48px; font-family:arial, 'helvetica neue', helvetica, sans-serif; font-size:40px; font-style:normal; font-weight:normal; color:#333333; text-align:center">
<strong><span t-field="o.initial_amount"/></strong>
</h3>
</div>
<div style="padding:0; margin:0px; padding-top:35px; padding-bottom:35px; background-color:#efefef; text-align:center;">
<p style="margin:0px; font-size:14px;font-family:arial, 'helvetica neue', helvetica, sans-serif; line-height:21px; color:#333333">
<strong>Gift Card Code</strong>
</p>
<p style="margin:0px; font-size:25px;font-family:arial, 'helvetica neue', helvetica, sans-serif; line-height:38px; color:#A9A9A9">
<span t-field="o.code"/>
</p>
</div>
<div style="padding:0; margin:0px; padding-top:10px; padding-bottom:10px; text-align:center;">
<h3 style="margin:0px; line-height:17px; font-family:arial, 'helvetica neue', helvetica, sans-serif; font-size:14px; font-style:normal; font-weight:normal; color:#A9A9A9; text-align:center">
Card expires <span t-field="o.expired_date"/>
</h3>
</div>
<div style="padding:0; margin:0px; padding-top:10px; padding-bottom:10px; text-align:center;">
<img t-att-src="'/report/barcode/Code128/'+o.code" style="width:200px;height:50px" alt="Barcode"/>
</div>
</t>
</t>
</t>
</template>
</data>
</odoo>
-282
View File
@@ -1,282 +0,0 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * pos_gift_card
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server saas~15.2\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-02-11 14:34+0000\n"
"PO-Revision-Date: 2022-02-11 14:34+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"
#. module: pos_gift_card
#: model_terms:ir.ui.view,arch_db:pos_gift_card.gift_card_template
msgid "<strong>Gift Card Code</strong>"
msgstr ""
#. module: pos_gift_card
#. openerp-web
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#, python-format
msgid "Amount of the gift card:"
msgstr ""
#. module: pos_gift_card
#: model_terms:ir.ui.view,arch_db:pos_gift_card.gift_card_template
msgid "Barcode"
msgstr ""
#. module: pos_gift_card
#: model:ir.model,name:pos_gift_card.model_barcode_rule
msgid "Barcode Rule"
msgstr ""
#. module: pos_gift_card
#: model:ir.model.fields,field_description:pos_gift_card.field_pos_order_line__generated_gift_card_ids
msgid "Bought Gift Card"
msgstr ""
#. module: pos_gift_card
#: model:ir.model.fields,field_description:pos_gift_card.field_gift_card__buy_pos_order_line_id
msgid "Buy Pos Order Line"
msgstr ""
#. module: pos_gift_card
#. openerp-web
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#, python-format
msgid "Cancel"
msgstr ""
#. module: pos_gift_card
#: model_terms:ir.ui.view,arch_db:pos_gift_card.gift_card_template
msgid "Card expires"
msgstr ""
#. module: pos_gift_card
#. openerp-web
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#, python-format
msgid "Check a gift card"
msgstr ""
#. module: pos_gift_card
#. openerp-web
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#, python-format
msgid "Confirm"
msgstr ""
#. module: pos_gift_card
#: model:ir.model.fields,help:pos_gift_card.field_pos_order_line__gift_card_id
msgid "Deducted from this Gift Card"
msgstr ""
#. module: pos_gift_card
#: model:ir.model.fields,help:pos_gift_card.field_pos_config__gift_card_settings
msgid "Defines the way you want to set your gift cards."
msgstr ""
#. module: pos_gift_card
#. openerp-web
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#, python-format
msgid "Discard"
msgstr ""
#. module: pos_gift_card
#: model:ir.model.fields.selection,name:pos_gift_card.selection__pos_config__gift_card_settings__create_set
msgid "Generate a new barcode and set a price"
msgstr ""
#. module: pos_gift_card
#. openerp-web
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#, python-format
msgid "Generate barcode"
msgstr ""
#. module: pos_gift_card
#. openerp-web
#: code:addons/pos_gift_card/static/src/xml/GiftCardButton.xml:0
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#: model:ir.actions.report,name:pos_gift_card.gift_card_report_pdf
#: model:ir.model,name:pos_gift_card.model_gift_card
#: model:ir.model.fields,field_description:pos_gift_card.field_pos_config__use_gift_card
#: model:ir.model.fields,field_description:pos_gift_card.field_pos_order_line__gift_card_id
#: model:ir.model.fields.selection,name:pos_gift_card.selection__barcode_rule__type__gift_card
#: model_terms:ir.ui.view,arch_db:pos_gift_card.pos_gift_card_config_view_form
#: model_terms:ir.ui.view,arch_db:pos_gift_card.res_config_view_form_inherit_pos_coupon
#, python-format
msgid "Gift Card"
msgstr ""
#. module: pos_gift_card
#. openerp-web
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#, python-format
msgid "Gift Card Barcode:"
msgstr ""
#. module: pos_gift_card
#: model:ir.model.fields,field_description:pos_gift_card.field_pos_order__gift_card_count
msgid "Gift Card Count"
msgstr ""
#. module: pos_gift_card
#. openerp-web
#: code:addons/pos_gift_card/static/src/js/PaymentScreen.js:0
#: code:addons/pos_gift_card/static/src/js/PaymentScreen.js:0
#, python-format
msgid "Gift Card Error"
msgstr ""
#. module: pos_gift_card
#: model:ir.model.fields,field_description:pos_gift_card.field_pos_config__gift_card_product_id
#: model_terms:ir.ui.view,arch_db:pos_gift_card.pos_gift_card_config_view_form
msgid "Gift Card Product"
msgstr ""
#. module: pos_gift_card
#: model:ir.ui.menu,name:pos_gift_card.pos_gift_card_menu
msgid "Gift Cards"
msgstr ""
#. module: pos_gift_card
#: model:ir.model.fields,field_description:pos_gift_card.field_pos_config__gift_card_settings
msgid "Gift Cards settings"
msgstr ""
#. module: pos_gift_card
#. openerp-web
#: code:addons/pos_gift_card/static/src/js/PaymentScreen.js:0
#, python-format
msgid "Gift card balance is too low."
msgstr ""
#. module: pos_gift_card
#. openerp-web
#: code:addons/pos_gift_card/static/src/js/PaymentScreen.js:0
#, python-format
msgid "Gift card is not valid."
msgstr ""
#. module: pos_gift_card
#: model_terms:ir.ui.view,arch_db:pos_gift_card.pos_gift_card_config_view_form
msgid "Gift card settings"
msgstr ""
#. module: pos_gift_card
#: model_terms:ir.ui.view,arch_db:pos_gift_card.gift_card_template
msgid "Here is your gift card!"
msgstr ""
#. module: pos_gift_card
#: model:ir.model,name:pos_gift_card.model_pos_config
msgid "Point of Sale Configuration"
msgstr ""
#. module: pos_gift_card
#: model:ir.model,name:pos_gift_card.model_pos_order_line
msgid "Point of Sale Order Lines"
msgstr ""
#. module: pos_gift_card
#: model:ir.model,name:pos_gift_card.model_pos_order
msgid "Point of Sale Orders"
msgstr ""
#. module: pos_gift_card
#: model:ir.model,name:pos_gift_card.model_pos_session
msgid "Point of Sale Session"
msgstr ""
#. module: pos_gift_card
#: model:ir.model.fields,help:pos_gift_card.field_gift_card__buy_pos_order_line_id
msgid "Pos Order line where this gift card has been bought."
msgstr ""
#. module: pos_gift_card
#: model:ir.model.fields,field_description:pos_gift_card.field_gift_card__redeem_pos_order_line_ids
msgid "Pos Redeems"
msgstr ""
#. module: pos_gift_card
#. openerp-web
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#, python-format
msgid "Remaining amount of the gift card:"
msgstr ""
#. module: pos_gift_card
#: model:ir.model.fields.selection,name:pos_gift_card.selection__pos_config__gift_card_settings__scan_set
msgid "Scan an existing barcode and set a price"
msgstr ""
#. module: pos_gift_card
#: model:ir.model.fields.selection,name:pos_gift_card.selection__pos_config__gift_card_settings__scan_use
msgid "Scan an existing barcode with an existing price"
msgstr ""
#. module: pos_gift_card
#. openerp-web
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#, python-format
msgid "Scan and set price on gift card"
msgstr ""
#. module: pos_gift_card
#. openerp-web
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#, python-format
msgid "Scan gift card"
msgstr ""
#. module: pos_gift_card
#. openerp-web
#: code:addons/pos_gift_card/static/src/js/GiftCardPopup.js:0
#, python-format
msgid "This gift card has already been sold"
msgstr ""
#. module: pos_gift_card
#: model:ir.model.fields,help:pos_gift_card.field_pos_config__gift_card_product_id
msgid "This product is used as reference on customer receipts."
msgstr ""
#. module: pos_gift_card
#: model:ir.model.fields,field_description:pos_gift_card.field_barcode_rule__type
msgid "Type"
msgstr ""
#. module: pos_gift_card
#. openerp-web
#: code:addons/pos_gift_card/static/src/xml/GiftCardPopup.xml:0
#, python-format
msgid "Use a gift card"
msgstr ""
#. module: pos_gift_card
#. openerp-web
#: code:addons/pos_gift_card/static/src/js/GiftCardPopup.js:0
#, python-format
msgid "You cannot sell a gift card that has already been sold"
msgstr ""
-9
View File
@@ -1,9 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import barcode_rule
from . import gift_card
from . import pos_config
from . import pos_order
from . import pos_order_line
from . import pos_session
@@ -1,14 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, fields
class BarcodeRule(models.Model):
_inherit = 'barcode.rule'
type = fields.Selection(selection_add=[
('gift_card', 'Gift Card'),
], ondelete={
'gift_card': 'set default',
})
-44
View File
@@ -1,44 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class GiftCard(models.Model):
_inherit = "gift.card"
buy_pos_order_line_id = fields.Many2one(
"pos.order.line",
copy=False,
readonly=True,
help="Pos Order line where this gift card has been bought.",
)
redeem_pos_order_line_ids = fields.One2many(
"pos.order.line", "gift_card_id", string="Pos Redeems"
)
@api.depends("redeem_pos_order_line_ids")
def _compute_balance(self):
super()._compute_balance()
for record in self:
confirmed_line = record.redeem_pos_order_line_ids.sudo().filtered(
lambda l: l.order_id.state in ('paid', 'done', 'invoiced')
)
balance = record.balance
if confirmed_line:
balance -= sum(
confirmed_line.mapped(
lambda line: line.currency_id._convert(
line.price_unit,
record.currency_id,
record.env.company,
line.create_date,
)
* -1
)
)
record.balance = balance
def can_be_used_in_pos(self):
# expired state are computed once a day, so can be not synchro
return self.state == 'valid' and self.balance > 0 and self.expired_date >= fields.Date.today()
-36
View File
@@ -1,36 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
class PosConfig(models.Model):
_inherit = "pos.config"
use_gift_card = fields.Boolean(string="Gift Card")
gift_card_product_id = fields.Many2one(
"product.product",
string="Gift Card Product",
help="This product is used as reference on customer receipts.",
)
gift_card_settings = fields.Selection(
[
("create_set", "Generate a new barcode and set a price"),
("scan_set", "Scan an existing barcode and set a price"),
("scan_use", "Scan an existing barcode with an existing price"),
],
string="Gift Cards settings",
default="create_set",
help="Defines the way you want to set your gift cards.",
)
@api.onchange("use_gift_card")
def _onchange_giftproduct(self):
if self.use_gift_card:
self.gift_card_product_id = self.env.ref(
"gift_card.pay_with_gift_card_product", False
)
else:
self.gift_card_product_id = False
-64
View File
@@ -1,64 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import api, fields, models
import base64
class PosOrder(models.Model):
_inherit = "pos.order"
gift_card_count = fields.Integer(compute="_compute_gift_card_count")
@api.depends("lines.generated_gift_card_ids")
def _compute_gift_card_count(self):
for record in self:
record.gift_card_count = len(record.lines.mapped("generated_gift_card_ids"))
@api.model
def create_from_ui(self, orders, draft=False):
order_ids = super(PosOrder, self).create_from_ui(orders, draft)
for order in self.sudo().browse([o["id"] for o in order_ids]):
gift_card_config = order.config_id.gift_card_settings
for line in order.lines:
if line.product_id.id == order.config_id.gift_card_product_id.id:
if not line.gift_card_id:
if gift_card_config == "create_set":
new_card = line._create_gift_cards()
new_card.partner_id = order.partner_id or False
line.generated_gift_card_ids = new_card
else:
gift_card = self.env["gift.card"].search(
[("id", "=", line.generated_gift_card_ids.id)]
)
gift_card.buy_pos_order_line_id = line.id
gift_card.expired_date = fields.Date.add(
fields.Date.today(), years=1
)
gift_card.partner_id = order.partner_id or False
if gift_card_config == "scan_set":
gift_card.initial_amount = line.price_unit
return order_ids
def get_new_card_ids(self):
return self.lines.mapped("generated_gift_card_ids").ids
def _add_mail_attachment(self, name, ticket):
attachment = super()._add_mail_attachment(name, ticket)
if self.config_id.use_gift_card and len(self.get_new_card_ids()) > 0:
report = self.env.ref('pos_gift_card.gift_card_report_pdf')._render_qweb_pdf(self.get_new_card_ids())
filename = name + '.pdf'
gift_card = self.env['ir.attachment'].create({
'name': filename,
'type': 'binary',
'datas': base64.b64encode(report[0]),
'store_fname': filename,
'res_model': 'pos.order',
'res_id': self.ids[0],
'mimetype': 'application/x-pdf'
})
attachment += [(4, gift_card.id)]
return attachment
@@ -1,34 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import fields, models
class PosOrderLine(models.Model):
_inherit = "pos.order.line"
generated_gift_card_ids = fields.One2many(
"gift.card", "buy_pos_order_line_id", string="Bought Gift Card"
)
gift_card_id = fields.Many2one(
"gift.card", help="Deducted from this Gift Card", copy=False
)
def _is_not_sellable_line(self):
return self.gift_card_id or super()._is_not_sellable_line()
def _create_gift_cards(self):
return self.env["gift.card"].create(
[self._build_gift_card() for _ in range(int(self.qty))]
)
def _build_gift_card(self):
return {
"initial_amount": self.order_id.currency_id._convert(
self.price_unit,
self.company_id.currency_id,
self.company_id,
fields.Date.today(),
),
"buy_pos_order_line_id": self.id,
}
@@ -1,15 +0,0 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
from odoo.osv.expression import OR
class PosSession(models.Model):
_inherit = 'pos.session'
def _loader_params_product_product(self):
result = super()._loader_params_product_product()
if self.config_id.use_gift_card and self.config_id.gift_card_product_id:
result['search_params']['domain'] = OR([result['search_params']['domain'], [('id', '=', self.config_id.gift_card_product_id.id)]])
return result
@@ -1,3 +0,0 @@
id,name,model_id/id,group_id/id,perm_read,perm_write,perm_create,perm_unlink
access_gift_card_sales,Gift Card Program Salesman,model_gift_card,point_of_sale.group_pos_manager,1,0,0,0
access_pos_gift_card_manager,Gift Card Program Sale Manager,model_gift_card,point_of_sale.group_pos_manager,1,1,1,1
1 id name model_id/id group_id/id perm_read perm_write perm_create perm_unlink
2 access_gift_card_sales Gift Card Program Salesman model_gift_card point_of_sale.group_pos_manager 1 0 0 0
3 access_pos_gift_card_manager Gift Card Program Sale Manager model_gift_card point_of_sale.group_pos_manager 1 1 1 1
@@ -1,46 +0,0 @@
.giftCardPopupMain {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
text-align: center;
padding: 1em;
}
.giftCardPopupContainer {
display: flex;
justify-content: center;
flex-wrap: wrap;
padding: 5px;
font-weight: bold;
text-align: center;
width: 100%;
}
.giftCardPopupFooter {
display: flex;
justify-content: space-evenly;
text-align: center;
}
.giftCardPopupInput {
border-bottom: 1px solid !important;
background-color: #F0EEEE !important;
box-shadow: none !important;
text-align: right !important;
}
.giftCardPopupButton {
width: auto !important;
height: auto !important;
padding: 10px;
}
.giftCardPopupConfirmButton {
flex-grow: 1;
height: auto !important;
padding: 10px;
}
@@ -1,30 +0,0 @@
odoo.define("pos_gift_card.GiftCardButton", function (require) {
"use strict";
const PosComponent = require("point_of_sale.PosComponent");
const ProductScreen = require("point_of_sale.ProductScreen");
const { useListener } = require("@web/core/utils/hooks");
const Registries = require("point_of_sale.Registries");
class GiftCardButton extends PosComponent {
setup() {
super.setup();
useListener("click", this.onClick);
}
async onClick() {
this.showPopup("GiftCardPopup", {});
}
}
GiftCardButton.template = "GiftCardButton";
ProductScreen.addControlButton({
component: GiftCardButton,
condition: function () {
return this.env.pos.config.use_gift_card;
},
});
Registries.Component.add(GiftCardButton);
return GiftCardButton;
});
@@ -1,158 +0,0 @@
odoo.define("pos_gift_card.GiftCardPopup", function (require) {
"use strict";
const AbstractAwaitablePopup = require("point_of_sale.AbstractAwaitablePopup");
const Registries = require("point_of_sale.Registries");
const { useState } = owl;
class GiftCardPopup extends AbstractAwaitablePopup {
setup() {
super.setup();
this.state = useState({
giftCardConfig: this.env.pos.config.gift_card_settings,
showBarcodeGeneration: false,
showNewGiftCardMenu: false,
showUseGiftCardMenu: false,
showGiftCardDetails: false,
amountToSet: 0,
giftCardBarcode: "",
});
}
switchBarcodeView() {
this.state.showBarcodeGeneration = !this.state.showBarcodeGeneration;
if (this.state.showUseGiftCardMenu)
this.state.showUseGiftCardMenu = false;
if (this.state.showGiftCardDetails)
this.state.showGiftCardDetails = false;
}
switchToUseGiftCardMenu() {
this.switchBarcodeView();
this.state.showUseGiftCardMenu = true;
}
switchToShowGiftCardDetails() {
this.switchBarcodeView();
this.state.showGiftCardDetails = true;
}
async addGiftCardProduct(giftCard) {
let gift =
this.env.pos.db.product_by_id[
this.env.pos.config.gift_card_product_id[0]
];
let can_be_sold = true;
if (giftCard) {
can_be_sold = !(giftCard.buy_pos_order_line_id || giftCard.buy_line_id);
}
if (can_be_sold) {
this.env.pos.get_order().add_product(gift, {
price: this.state.amountToSet,
quantity: 1,
merge: false,
generated_gift_card_ids: giftCard ? giftCard.id : false,
extras: { price_manually_set: true },
});
} else {
await this.showPopup('ErrorPopup', {
'title': this.env._t('This gift card has already been sold'),
'body': this.env._t('You cannot sell a gift card that has already been sold'),
});
}
}
async getGiftCard() {
if (this.state.giftCardBarcode == "") return;
let giftCard = await this.rpc({
model: "gift.card",
method: "search_read",
args: [[["code", "=", this.state.giftCardBarcode]]],
});
if (giftCard.length) {
giftCard = giftCard[0];
} else {
return false;
}
return giftCard;
}
async scanAndUseGiftCard() {
let giftCard = await this.getGiftCard();
if (!giftCard) return;
if (this.state.giftCardConfig === "scan_use")
this.state.amountToSet = giftCard.initial_amount;
await this.addGiftCardProduct(giftCard);
this.cancel();
}
async generateBarcode() {
await this.addGiftCardProduct(false);
this.confirm();
}
async isGiftCardAlreadyUsed() {
let order = this.env.pos.get_order();
let giftProduct =
this.env.pos.db.product_by_id[
this.env.pos.config.gift_card_product_id[0]
];
for (let line of order.orderlines) {
if (line.product.id === giftProduct.id && line.price < 0) {
if (line.gift_card_id === await this.getGiftCard().id) return line;
}
}
return false;
}
getPriceToRemove(giftCard) {
let currentOrder = this.env.pos.get_order();
return currentOrder.get_total_with_tax() > giftCard.balance
? -giftCard.balance
: -currentOrder.get_total_with_tax();
}
async payWithGiftCard() {
let giftCard = await this.getGiftCard();
if (!giftCard) return;
let gift =
this.env.pos.db.product_by_id[
this.env.pos.config.gift_card_product_id[0]
];
let currentOrder = this.env.pos.get_order();
let lineUsed = this.isGiftCardAlreadyUsed()
if (lineUsed) currentOrder.remove_orderline(lineUsed);
currentOrder.add_product(gift, {
price: this.getPriceToRemove(giftCard),
quantity: 1,
merge: false,
gift_card_id: giftCard.id,
});
this.cancel();
}
async ShowRemainingAmount() {
let giftCard = await this.getGiftCard();
if (!giftCard) return;
this.state.amountToSet = giftCard.balance;
}
}
GiftCardPopup.template = "GiftCardPopup";
Registries.Component.add(GiftCardPopup);
return GiftCardPopup;
});
@@ -1,80 +0,0 @@
odoo.define('pos_gift_card.PaymentScreen', function(require) {
"use strict";
const PaymentScreen = require('point_of_sale.PaymentScreen');
const Registries = require('point_of_sale.Registries');
var core = require('web.core');
var _t = core._t;
const PosGiftCardPaymentScreen = PaymentScreen => class extends PaymentScreen {
//@Override
async validateOrder(isForceValidate) {
if(this.env.pos.config.use_gift_card) {
if (await this._isOrderValid(isForceValidate)) {
try {
let giftProduct = this.env.pos.db.product_by_id[this.env.pos.config.gift_card_product_id[0]];
for (let line of this.currentOrder.orderlines) {
if(line.product.id === giftProduct.id && line.price <= 0) {
let is_valid = await this.rpc({
model: "gift.card",
method: 'can_be_used_in_pos',
args: [line.gift_card_id],
});
if(!is_valid) {
await this.showPopup('ErrorPopup', {
'title': _t("Gift Card Error"),
'body': _t("Gift card is not valid."),
});
return;
}
let gift_card = await this.rpc({
model: "gift.card",
method: 'search_read',
domain: [['id', '=', line.gift_card_id]],
fields: ['balance'],
});
if(Math.abs(line.price) > gift_card[0].balance) {
await this.showPopup('ErrorPopup', {
'title': _t("Gift Card Error"),
'body': _t("Gift card balance is too low."),
});
return;
}
}
}
} catch (_e) {
// do nothing with the error
}
}
}
await super.validateOrder(...arguments);
}
async _postPushOrderResolve(order, server_ids) {
if(this.env.pos.config.use_gift_card) {
let ids = await this.rpc({
model: 'pos.order',
method: 'get_new_card_ids',
args: [server_ids]
});
if (ids.length > 0) {
this.env.legacyActionManager.do_action('pos_gift_card.gift_card_report_pdf', {
additional_context: {
active_ids: [ids],
},
});
}
}
return super._postPushOrderResolve(order, server_ids);
}
};
Registries.Component.extend(PaymentScreen, PosGiftCardPaymentScreen);
return PosGiftCardPaymentScreen;
});
@@ -1,46 +0,0 @@
odoo.define("pos_gift_card.gift_card", function (require) {
"use strict";
const { Order, Orderline } = require("point_of_sale.models");
const Registries = require('point_of_sale.Registries');
const PosGiftCardOrder = (Order) => class PosGiftCardOrder extends Order {
set_orderline_options(orderline, options) {
super.set_orderline_options(...arguments);
if (options && options.generated_gift_card_ids) {
orderline.generated_gift_card_ids = [options.generated_gift_card_ids];
}
if (options && options.gift_card_id) {
orderline.gift_card_id = options.gift_card_id;
}
}
wait_for_push_order() {
if(this.pos.config.use_gift_card) {
let giftProduct = this.pos.db.product_by_id[this.pos.config.gift_card_product_id[0]];
for (let line of this.orderlines) {
if(line.product.id === giftProduct.id)
return true;
}
}
return super.wait_for_push_order(...arguments);
}
}
Registries.Model.extend(Order, PosGiftCardOrder);
const PosGiftCardOrderline = (Orderline) => class PosGiftCardOrderline extends Orderline {
export_as_JSON() {
var json = super.export_as_JSON(...arguments);
json.generated_gift_card_ids = this.generated_gift_card_ids;
json.gift_card_id = this.gift_card_id;
return json;
}
init_from_JSON(json) {
super.init_from_JSON(...arguments);
this.generated_gift_card_ids = json.generated_gift_card_ids;
this.gift_card_id = json.gift_card_id;
}
}
Registries.Model.extend(Orderline, PosGiftCardOrderline);
});
@@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="GiftCardButton" owl="1">
<span class="control-button">
<i class="fa fa-gift"></i>
<span> </span>
<span>Gift Card</span>
</span>
</t>
</templates>
@@ -1,138 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="GiftCardPopup" owl="1">
<Draggable>
<div class="popup popup-textarea">
<header class="title drag-handle">
Gift Card
</header>
<main class="giftCardPopupMain">
<div class="giftCardPopupContainer" t-if="!state.showBarcodeGeneration">
<span t-if="state.giftCardConfig == 'create_set'"
class="giftCardPopupButton button"
t-on-click="switchBarcodeView">Generate barcode</span>
<span t-if="state.giftCardConfig == 'scan_set'"
class="giftCardPopupButton button"
t-on-click="switchBarcodeView">Scan and set price on gift card</span>
<span t-if="state.giftCardConfig == 'scan_use'"
class="giftCardPopupButton button"
t-on-click="switchBarcodeView">Scan gift card</span>
</div>
<div t-if="!state.showUseGiftCardMenu &amp;&amp; !state.showGiftCardDetails">
<div class="giftCardPopupContainer"
t-if="state.showBarcodeGeneration &amp;&amp; state.giftCardConfig == 'create_set'">
<div>
<span>Amount of the gift card:</span><br/>
<div>
<input t-model.number="state.amountToSet" class="giftCardPopupInput" type="text"/>
<span class="currency">
<t t-esc="env.pos.getCurrencySymbol()" />
</span>
</div>
</div>
<div>
<div class="button confirm" t-on-click="generateBarcode">
Confirm
</div>
<div class="button confirm" t-on-click="switchBarcodeView">
Cancel
</div>
</div>
</div>
<div class="giftCardPopupContainer"
t-if="state.showBarcodeGeneration &amp;&amp; state.giftCardConfig == 'scan_set'">
<div>
Gift Card Barcode: <br/>
<input t-model="state.giftCardBarcode" class="giftCardPopupInput" type="text"/>
</div>
<div>
Amount of the gift card: <br/>
<input t-model.number="state.amountToSet" class="giftCardPopupInput" type="text"/>
</div>
<div>
<span class="button confirm" t-on-click="scanAndUseGiftCard">
Confirm
</span>
<span class="button cancel" t-on-click="switchBarcodeView">
Discard
</span>
</div>
</div>
<div class="giftCardPopupContainer"
t-if="state.showBarcodeGeneration &amp;&amp; state.giftCardConfig == 'scan_use'">
<div>
Gift Card Barcode:
<input t-model="state.giftCardBarcode" class="giftCardPopupInput" type="text"/>
</div>
<div>
<span class="button confirm" t-on-click="scanAndUseGiftCard">
Confirm
</span>
<span class="button cancel" t-on-click="switchBarcodeView">
Discard
</span>
</div>
</div>
</div>
<div class="giftCardPopupContainer"
t-if="state.showBarcodeGeneration &amp;&amp; state.showUseGiftCardMenu">
<div>
Gift Card Barcode:
<input t-model="state.giftCardBarcode" class="giftCardPopupInput" type="text"/>
</div>
<div>
<span class="button confirm" t-on-click="payWithGiftCard">
Confirm
</span>
<span class="button cancel" t-on-click="switchBarcodeView">
Discard
</span>
</div>
</div>
<div class="giftCardPopupContainer"
t-if="state.showBarcodeGeneration &amp;&amp; state.showGiftCardDetails">
<div>
Gift Card Barcode:
<input t-model="state.giftCardBarcode" class="giftCardPopupInput" type="text"/>
</div>
<div>
Remaining amount of the gift card:
<t t-esc="state.amountToSet"/>
</div>
<div>
<span class="button confirm" t-on-click="ShowRemainingAmount">
Confirm
</span>
<span class="button cancel" t-on-click="switchBarcodeView">
Discard
</span>
</div>
</div>
<div class="giftCardPopupContainer" t-if="!state.showBarcodeGeneration">
<div class="button giftCardPopupConfirmButton" t-on-click="switchToUseGiftCardMenu">
Use a gift card
</div>
<div class="button giftCardPopupConfirmButton" t-on-click="switchToShowGiftCardDetails">
Check a gift card
</div>
</div>
</main>
<footer class="footer giftCardPopupFooter">
<div class="button cancel" t-on-click="cancel">
Cancel
</div>
</footer>
</div>
</Draggable>
</t>
</templates>
@@ -1,33 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<menuitem
id="pos_gift_card_menu"
action="gift_card.gift_card_action"
parent="point_of_sale.pos_config_menu_catalog"
name="Gift Cards"
groups="point_of_sale.group_pos_manager"
sequence="100"
/>
<record id="pos_gift_card_view_form" model="ir.ui.view">
<field name="name">gift.card.form Website</field>
<field name="model">gift.card</field>
<field name="inherit_id" ref="gift_card.gift_card_view_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='code']" position="after">
<field name="buy_pos_order_line_id" options="{'no_create': True}"/>
</xpath>
<xpath expr="//group[@name='gift_card']" position="after">
<group>
<field name="redeem_pos_order_line_ids" options="{'no_create': True}" readonly="1">
<tree>
<field name="id"/>
</tree>
</field>
</group>
</xpath>
</field>
</record>
</odoo>
@@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="pos_gift_card_config_view_form" model="ir.ui.view">
<field name="name">pos.config.form</field>
<field name="model">pos.config</field>
<field name="inherit_id" ref="point_of_sale.pos_config_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@id='pos-loyalty']" position="after">
<div class="col-12 col-lg-6 o_setting_box" id="pos-coupon">
<div class="o_setting_left_pane">
<field name="use_gift_card"/>
</div>
<div class="o_setting_right_pane" title="Gift Card">
<label for="use_gift_card"/>
<div class="content-group" attrs="{'invisible': [('use_gift_card', '=', False)]}">
<div class="mt16" id="gift_card_product">
<label string="Gift Card Product" for="gift_card_product_id" class="o_light_label"/>
<field name="gift_card_product_id"/><br/>
<button name="%(gift_card.gift_card_action)d" icon="fa-arrow-right" type="action" string="Gift Card" class="btn-link"/><br/>
<label for="gift_card_settings" string="Gift card settings"/>
<field name="gift_card_settings" widget="radio"/>
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>
</odoo>
@@ -1,15 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="res_config_view_form_inherit_pos_coupon" model="ir.ui.view">
<field name="name">res.config.form.inherit.pos.coupon</field>
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="point_of_sale.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[@id='pos-gift-card']/div[last()]" position="after">
<div class="mt8" attrs="{'invisible': [('module_pos_gift_card', '=', False)]}">
<button name="%(gift_card.gift_card_action)d" icon="fa-arrow-right" type="action" string="Gift Card" class="btn-link"/><br/>
</div>
</xpath>
</field>
</record>
</odoo>