From 8e6001b119f5956f5e7533982992587e350b4a7e Mon Sep 17 00:00:00 2001 From: Sergey Krylov Date: Wed, 19 Feb 2025 14:12:32 +0300 Subject: [PATCH] =?UTF-8?q?=D0=9D=D0=B0=D1=87=D0=B0=D0=BB=D1=8C=D0=BD?= =?UTF-8?q?=D0=BE=D0=B5=20=D0=BD=D0=B0=D0=BF=D0=BE=D0=BB=D0=BD=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __init__.py | 4 +++ __manifest__.py | 18 ++++++++++++ i18n/pos_restaurant_stripe.pot | 26 +++++++++++++++++ i18n/ru.po | 28 +++++++++++++++++++ models/__init__.py | 5 ++++ models/pos_order.py | 17 +++++++++++ models/pos_payment.py | 16 +++++++++++ static/src/overrides/models/payment_stripe.js | 25 +++++++++++++++++ 8 files changed, 139 insertions(+) create mode 100644 __init__.py create mode 100644 __manifest__.py create mode 100644 i18n/pos_restaurant_stripe.pot create mode 100644 i18n/ru.po create mode 100644 models/__init__.py create mode 100644 models/pos_order.py create mode 100644 models/pos_payment.py create mode 100644 static/src/overrides/models/payment_stripe.js diff --git a/__init__.py b/__init__.py new file mode 100644 index 0000000..dc5e6b6 --- /dev/null +++ b/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import models diff --git a/__manifest__.py b/__manifest__.py new file mode 100644 index 0000000..b368410 --- /dev/null +++ b/__manifest__.py @@ -0,0 +1,18 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +{ + 'name': 'POS Restaurant Stripe', + 'version': '1.0', + 'category': 'Point of Sale', + 'sequence': 6, + 'summary': 'Adds American style tipping to Stripe', + 'depends': ['pos_stripe', 'pos_restaurant', 'payment_stripe'], + 'auto_install': True, + 'assets': { + 'point_of_sale._assets_pos': [ + 'pos_restaurant_stripe/static/**/*', + ], + }, + 'license': 'LGPL-3', +} diff --git a/i18n/pos_restaurant_stripe.pot b/i18n/pos_restaurant_stripe.pot new file mode 100644 index 0000000..7bb6ba6 --- /dev/null +++ b/i18n/pos_restaurant_stripe.pot @@ -0,0 +1,26 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_restaurant_stripe +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-10-26 21:55+0000\n" +"PO-Revision-Date: 2023-10-26 21:55+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_restaurant_stripe +#: model:ir.model,name:pos_restaurant_stripe.model_pos_order +msgid "Point of Sale Orders" +msgstr "" + +#. module: pos_restaurant_stripe +#: model:ir.model,name:pos_restaurant_stripe.model_pos_payment +msgid "Point of Sale Payments" +msgstr "" diff --git a/i18n/ru.po b/i18n/ru.po new file mode 100644 index 0000000..86378e5 --- /dev/null +++ b/i18n/ru.po @@ -0,0 +1,28 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * pos_restaurant_stripe +# +# Translators: +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 17.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-10-26 21:55+0000\n" +"PO-Revision-Date: 2024-01-30 15:14+0400\n" +"Last-Translator: \n" +"Language-Team: Russian (https://app.transifex.com/odoo/teams/41243/ru/)\n" +"Language: ru\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: nplurals=4; plural=(n%10==1 && n%100!=11 ? 0 : n%10>=2 && n%10<=4 && (n%100<12 || n%100>14) ? 1 : n%10==0 || (n%10>=5 && n%10<=9) || (n%100>=11 && n%100<=14)? 2 : 3);\n" + +#. module: pos_restaurant_stripe +#: model:ir.model,name:pos_restaurant_stripe.model_pos_order +msgid "Point of Sale Orders" +msgstr "Заказы в торговых точках" + +#. module: pos_restaurant_stripe +#: model:ir.model,name:pos_restaurant_stripe.model_pos_payment +msgid "Point of Sale Payments" +msgstr "Платежи в точках продаж" diff --git a/models/__init__.py b/models/__init__.py new file mode 100644 index 0000000..f3a2a58 --- /dev/null +++ b/models/__init__.py @@ -0,0 +1,5 @@ +# coding: utf-8 +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import pos_payment +from . import pos_order diff --git a/models/pos_order.py b/models/pos_order.py new file mode 100644 index 0000000..8a338ad --- /dev/null +++ b/models/pos_order.py @@ -0,0 +1,17 @@ +# coding: utf-8 +# Part of Odoo. See LICENSE file for full copyright and licensing details. +from odoo import models + + +class PosOrder(models.Model): + _inherit = 'pos.order' + + def set_no_tip(self): + """Capture the payment when no tip is set.""" + res = super(PosOrder, self).set_no_tip() + + for payment in self.payment_ids: + if payment.payment_method_id.use_payment_terminal == 'stripe': + payment.payment_method_id.stripe_capture_payment(payment.transaction_id) + + return res diff --git a/models/pos_payment.py b/models/pos_payment.py new file mode 100644 index 0000000..cbf3dd4 --- /dev/null +++ b/models/pos_payment.py @@ -0,0 +1,16 @@ +# coding: utf-8 +# Part of Odoo. See LICENSE file for full copyright and licensing details. +from odoo import models + + +class PosPayment(models.Model): + _inherit = 'pos.payment' + + def _update_payment_line_for_tip(self, tip_amount): + """Capture the payment when a tip is set.""" + res = super(PosPayment, self)._update_payment_line_for_tip(tip_amount) + + if self.payment_method_id.use_payment_terminal == 'stripe': + self.payment_method_id.stripe_capture_payment(self.transaction_id, amount=self.amount) + + return res diff --git a/static/src/overrides/models/payment_stripe.js b/static/src/overrides/models/payment_stripe.js new file mode 100644 index 0000000..dd76975 --- /dev/null +++ b/static/src/overrides/models/payment_stripe.js @@ -0,0 +1,25 @@ +/** @odoo-module */ + +import { PaymentStripe } from "@pos_stripe/app/payment_stripe"; +import { patch } from "@web/core/utils/patch"; + +patch(PaymentStripe.prototype, { + async captureAfterPayment(processPayment, line) { + // Don't capture if the customer can tip, in that case we + // will capture later. + if (!this.canBeAdjusted(line.cid)) { + return super.captureAfterPayment(...arguments); + } + }, + + canBeAdjusted(cid) { + var order = this.pos.get_order(); + var line = order.get_paymentline(cid); + return ( + this.pos.config.set_tip_after_payment && + line.payment_method.use_payment_terminal === "stripe" && + line.card_type !== "interac" && + !line.card_type.includes("eftpos") + ); + }, +});