Skip to content

Commit

Permalink
[14.0][ADD] shopinvader_payment_gift_card module
Browse files Browse the repository at this point in the history
  • Loading branch information
Kev-Roche committed Apr 7, 2022
1 parent 7059f93 commit c2a3fed
Show file tree
Hide file tree
Showing 15 changed files with 798 additions and 0 deletions.
6 changes: 6 additions & 0 deletions setup/shopinvader_payment_gift_card/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
2 changes: 2 additions & 0 deletions shopinvader_payment_gift_card/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import models
from . import services
25 changes: 25 additions & 0 deletions shopinvader_payment_gift_card/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Copyright 2021 Akretion (https://www.akretion.com).
# @author Kévin Roche <[email protected]>
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "shopinvader_payment_gift_card",
"summary": "Shopinvader Services for Gift Cards and Payments with",
"version": "14.0.1.0.0",
"category": "e-commerce",
"website": "https://github.com/shopinvader/odoo-shopinvader-payment",
"author": "Akretion, Odoo Community Association (OCA)",
"maintainers": ["Kev-Roche"],
"license": "AGPL-3",
"application": False,
"installable": True,
"depends": [
"shopinvader_payment",
"shopinvader_gift_card",
"account_payment_gift_card",
"base_rest",
"base_jsonify",
"base_rest_datamodel",
"shopinvader_payment_manual",
],
}
143 changes: 143 additions & 0 deletions shopinvader_payment_gift_card/i18n/fr.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * shopinvader_payment_gift_card
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-02-24 22:26+0000\n"
"PO-Revision-Date: 2022-02-24 23:30+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"
"Language: fr\n"
"X-Generator: Poedit 3.0\n"

#. module: shopinvader_payment_gift_card
#: model:mail.template,body_html:shopinvader_payment_gift_card.email_gift_card_confirmation
#: model:mail.template,body_html:shopinvader_payment_gift_card.email_gift_card_confirmation_notification
msgid " Thanks for buying a gift card "
msgstr " Merci d'avoir acheter une carte cadeau chez nous "

#. module: shopinvader_payment_gift_card
#: model:mail.template,body_html:shopinvader_payment_gift_card.email_gift_card_activation
#: model:mail.template,body_html:shopinvader_payment_gift_card.email_gift_card_activation_notification
msgid " You receive a gift card !"
msgstr " Vous avez reçu une carte cadeau!"

#. module: shopinvader_payment_gift_card
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_gift_card__beneficiary_email
msgid "Beneficiary Email"
msgstr "Email Bénéficiaire"

#. module: shopinvader_payment_gift_card
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_gift_card__beneficiary_name
msgid "Beneficiary Name"
msgstr "Nom Bénéficiaire"

#. module: shopinvader_payment_gift_card
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_gift_card__buyer_email
msgid "Buyer Email"
msgstr "Email Acheteur"

#. module: shopinvader_payment_gift_card
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_gift_card__buyer_name
msgid "Buyer Name"
msgstr "Nom Acheteur"

#. module: shopinvader_payment_gift_card
#: model:mail.template,subject:shopinvader_payment_gift_card.email_gift_card_activation
#: model:mail.template,subject:shopinvader_payment_gift_card.email_gift_card_activation_notification
msgid "Cart notification ${object.name}"
msgstr ""

#. module: shopinvader_payment_gift_card
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_gift_card__comment
msgid "Comment"
msgstr ""

#. module: shopinvader_payment_gift_card
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_account_move__display_name
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_gift_card__display_name
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_sale_order_line__display_name
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_shopinvader_notification__display_name
msgid "Display Name"
msgstr "Nom affiché"

#. module: shopinvader_payment_gift_card
#: model:ir.model.fields.selection,name:shopinvader_payment_gift_card.selection__gift_card__state__draft
msgid "Draft"
msgstr ""

#. module: shopinvader_payment_gift_card
#: code:addons/shopinvader_payment_gift_card/models/shopinvader_notification.py:0
#, python-format
msgid "Email Gift card created to the Buyer"
msgstr "Émail création Carte Cadeau à l'acheteur"

#. module: shopinvader_payment_gift_card
#: code:addons/shopinvader_payment_gift_card/models/shopinvader_notification.py:0
#, python-format
msgid "Email gift Card to the Beneficiary"
msgstr "Émail Activation Carte Cadeau au Bénéficiaire"

#. module: shopinvader_payment_gift_card
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_sale_order_line__gift_card_id
msgid "Gift Card"
msgstr ""

#. module: shopinvader_payment_gift_card
#: model:ir.model,name:shopinvader_payment_gift_card.model_gift_card
msgid "Gift Card Customizable"
msgstr ""

#. module: shopinvader_payment_gift_card
#: model:mail.template,subject:shopinvader_payment_gift_card.email_gift_card_confirmation
#: model:mail.template,subject:shopinvader_payment_gift_card.email_gift_card_confirmation_notification
msgid "Gift card created notification ${object.name}"
msgstr ""

#. module: shopinvader_payment_gift_card
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_account_move__id
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_gift_card__id
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_sale_order_line__id
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_shopinvader_notification__id
msgid "ID"
msgstr ""

#. module: shopinvader_payment_gift_card
#: model:ir.model,name:shopinvader_payment_gift_card.model_account_move
msgid "Journal Entry"
msgstr "Pièce comptable"

#. module: shopinvader_payment_gift_card
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_account_move____last_update
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_gift_card____last_update
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_sale_order_line____last_update
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_shopinvader_notification____last_update
msgid "Last Modified on"
msgstr "Dernière modification le"

#. module: shopinvader_payment_gift_card
#: model:ir.model,name:shopinvader_payment_gift_card.model_sale_order_line
msgid "Sales Order Line"
msgstr "Lignes de bon de commande"

#. module: shopinvader_payment_gift_card
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_gift_card__user_id
msgid "Salesperson"
msgstr ""

#. module: shopinvader_payment_gift_card
#: model:ir.model,name:shopinvader_payment_gift_card.model_shopinvader_notification
msgid "Shopinvader Notification"
msgstr ""

#. module: shopinvader_payment_gift_card
#: model:ir.model.fields,field_description:shopinvader_payment_gift_card.field_gift_card__state
msgid "State"
msgstr "Etat"
2 changes: 2 additions & 0 deletions shopinvader_payment_gift_card/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import sale
from . import payment_transaction
47 changes: 47 additions & 0 deletions shopinvader_payment_gift_card/models/payment_transaction.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Copyright (C) 2022 Akretion (<http://www.akretion.com>).
# @author Kévin Roche <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import models


class PaymentTransaction(models.Model):
_inherit = "payment.transaction"

def _check_amount_and_confirm_order(self):
self.ensure_one()
for order in self.sale_order_ids.filtered(
lambda so: so.state in ("draft", "sent")
):
if (
self.amount == order.remain_amount
and order.amount_total
== order.remain_amount
+ sum(order.gift_card_line_ids.mapped("amount_used"))
):
order.with_context(send_email=True).action_confirm()
else:
return super()._check_amount_and_confirm_order()

def _post_process_after_done(self):
res = super()._post_process_after_done()
if self.sale_order_ids.gift_card_line_ids:
for gift_card_line in self.sale_order_ids.gift_card_line_ids:
if not gift_card_line.transaction_id:
self._add_gift_card_transaction(amount=gift_card_line.amount_used, line=gift_card_line)
return res


def create_gift_card_payment(self, sale):
gift_card_acquirer = self.env.ref('account_payment_gift_card.payment_acquirer_gift_card')
for line in sale.gift_card_line_ids:
vals = {
"acquirer_id": gift_card_acquirer.id,
"amount": line.amount_used,
}
transaction = sale._create_payment_transaction(vals)
transaction._create_payment()
line.transaction_id = transaction



41 changes: 41 additions & 0 deletions shopinvader_payment_gift_card/models/sale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Copyright (C) 2022 Akretion (<http://www.akretion.com>).
# @author Kévin Roche <[email protected]>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


class SaleOrder(models.Model):
_inherit = "sale.order"

gift_card_line_ids = fields.One2many(
"gift.card.line",
inverse_name="sale_order_id",
string="List of Gift Card uses",
readonly=True,
)

remain_amount = fields.Float("Remaining Amount", compute="_compute_remain_amount")

@api.depends("gift_card_line_ids", "gift_card_line_ids.amount_used", "amount_total")
def _compute_remain_amount(self):
for rec in self:
if rec.gift_card_line_ids:
gift_card_amount_total = sum(
line.amount_used for line in rec.gift_card_line_ids
)
rec.remain_amount = rec.amount_total - gift_card_amount_total
else:
rec.remain_amount = rec.amount_total

def _invader_prepare_payment_transaction_data(self, acquirer_id):
vals = super()._invader_prepare_payment_transaction_data(acquirer_id)
if self.gift_card_line_ids:
vals["amount"] = self.remain_amount
return vals


class SaleOrderLine(models.Model):
_inherit = "sale.order.line"

gift_card_id = fields.Many2one("gift.card")
2 changes: 2 additions & 0 deletions shopinvader_payment_gift_card/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
* Kévin Roche <[email protected]>
* Pierrick Brun <[email protected]>
1 change: 1 addition & 0 deletions shopinvader_payment_gift_card/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Services for Gift Cards Transactions and Payments
2 changes: 2 additions & 0 deletions shopinvader_payment_gift_card/services/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import cart
from . import payment_gift_card
Loading

0 comments on commit c2a3fed

Please sign in to comment.