From aa028b93bb7884fa9f54974dd8132f1cbc198d97 Mon Sep 17 00:00:00 2001 From: Alfredo Date: Mon, 21 Oct 2024 13:38:48 +0200 Subject: [PATCH 1/6] [FIX] stock_picking_create_repair: change calculations. --- stock_picking_create_repair/models/repair_fee.py | 6 +----- stock_picking_create_repair/models/repair_line.py | 6 +----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/stock_picking_create_repair/models/repair_fee.py b/stock_picking_create_repair/models/repair_fee.py index 590cbda6bc..a4a7c83ba3 100644 --- a/stock_picking_create_repair/models/repair_fee.py +++ b/stock_picking_create_repair/models/repair_fee.py @@ -33,8 +33,4 @@ def _put_amount_untaxed_in_price_in_sale_budget(self): and x.repair_id.sale_order_id and x.repair_id.sale_order_id.is_repair ): - fee.repair_id.price_in_sale_budget = ( - 0 - if not fee.repair_id.product_qty - else fee.repair_id.amount_untaxed / fee.repair_id.product_qty - ) + fee.repair_id.price_in_sale_budget = fee.repair_id.amount_untaxed diff --git a/stock_picking_create_repair/models/repair_line.py b/stock_picking_create_repair/models/repair_line.py index cf35050ffa..bde12e75ca 100644 --- a/stock_picking_create_repair/models/repair_line.py +++ b/stock_picking_create_repair/models/repair_line.py @@ -25,8 +25,4 @@ def _put_amount_untaxed_in_price_in_sale_budget(self): and x.repair_id.sale_order_id and x.repair_id.sale_order_id.is_repair ): - line.repair_id.price_in_sale_budget = ( - 0 - if not line.repair_id.product_qty - else line.repair_id.amount_untaxed / line.repair_id.product_qty - ) + line.repair_id.price_in_sale_budget = line.repair_id.amount_untaxed From 683f61b622b4db6f6683020791462338240ac94e Mon Sep 17 00:00:00 2001 From: Tu Nombre Date: Tue, 22 Oct 2024 10:04:00 +0200 Subject: [PATCH 2/6] [14.0][IMP] purchase_open_qty_totals: Add in other purchase tree view. --- .../views/purchase_order_view.xml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/purchase_open_qty_totals/views/purchase_order_view.xml b/purchase_open_qty_totals/views/purchase_order_view.xml index ed44e66687..91df9a520e 100644 --- a/purchase_open_qty_totals/views/purchase_order_view.xml +++ b/purchase_open_qty_totals/views/purchase_order_view.xml @@ -27,4 +27,18 @@ + + + purchase.order + + + + + + + + + + + From de1ced2de953b5dd806734bb4c3808f0e3fb123b Mon Sep 17 00:00:00 2001 From: Tu Nombre Date: Fri, 18 Oct 2024 10:45:05 +0200 Subject: [PATCH 3/6] [14.0][IMP] purchase_order_shipping_method: Add store true to a conpute fieldd --- .../__manifest__.py | 3 ++- .../migrations/14.0.1.1.0/pre-migration.py | 27 +++++++++++++++++++ .../models/stock_picking.py | 9 ++++--- 3 files changed, 35 insertions(+), 4 deletions(-) create mode 100644 purchase_order_shipping_method/migrations/14.0.1.1.0/pre-migration.py diff --git a/purchase_order_shipping_method/__manifest__.py b/purchase_order_shipping_method/__manifest__.py index 4d9fc63bd3..2d8af426d4 100644 --- a/purchase_order_shipping_method/__manifest__.py +++ b/purchase_order_shipping_method/__manifest__.py @@ -3,7 +3,7 @@ { "name": "Purchase Order Shipping Method", - "version": "14.0.1.0.0", + "version": "14.0.1.1.0", "category": "Sales", "license": "AGPL-3", "author": "AvanzOSC", @@ -25,4 +25,5 @@ "views/transport_carrier_lines_to_invoice_view.xml", ], "installable": True, + "pre_init_hook": "pre_init_hook", } diff --git a/purchase_order_shipping_method/migrations/14.0.1.1.0/pre-migration.py b/purchase_order_shipping_method/migrations/14.0.1.1.0/pre-migration.py new file mode 100644 index 0000000000..614d357aaf --- /dev/null +++ b/purchase_order_shipping_method/migrations/14.0.1.1.0/pre-migration.py @@ -0,0 +1,27 @@ +# Copyright 2024 Berezi Amubieta - AvanzOSC +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +import logging + +from openupgradelib import openupgrade + +_logger = logging.getLogger(__name__) + + +@openupgrade.migrate() +def migrate(env, version): + cr = env.cr + if not openupgrade.column_exists(cr, "stock_picking", "total_done_qty"): + cr.execute( + """ + ALTER TABLE stock_picking + ADD COLUMN total_done_qty float; + """ + ) + cr.execute( + """ + UPDATE stock_picking + SET total_done_qty = (SELECT SUM(qty_done) + FROM stock_move_line + WHERE stock_move_line.picking_id = stock_picking.id) + """ + ) diff --git a/purchase_order_shipping_method/models/stock_picking.py b/purchase_order_shipping_method/models/stock_picking.py index 3215243154..de730cc420 100644 --- a/purchase_order_shipping_method/models/stock_picking.py +++ b/purchase_order_shipping_method/models/stock_picking.py @@ -24,18 +24,21 @@ class StockPicking(models.Model): ) license_plate = fields.Char(string="Transport License Plate") total_done_qty = fields.Float( - string="Total Done Quantity", compute="_compute_total_done_qty" + string="Total Done Quantity", compute="_compute_total_done_qty", store=True ) transport_price = fields.Float( string="Transport Price", compute="_compute_transport_price" ) + @api.depends( + "move_line_ids_without_package", "move_line_ids_without_package.qty_done" + ) def _compute_total_done_qty(self): for picking in self: picking.total_done_qty = 0 - if picking.move_ids_without_package: + if picking.move_line_ids_without_package: picking.total_done_qty = sum( - picking.move_ids_without_package.mapped("quantity_done") + picking.move_line_ids_without_package.mapped("qty_done") ) def _compute_transport_price(self): From 716f528b550724b55a1360a131a68a4dc6fe6863 Mon Sep 17 00:00:00 2001 From: Tu Nombre Date: Tue, 22 Oct 2024 08:26:50 +0200 Subject: [PATCH 4/6] [14.0][ADD] custom_purchase_import_wizard: Change menu ids. --- .../i18n/custom_purchase_import_wizard.pot | 19 ++++++++++------- custom_purchase_import_wizard/i18n/es.po | 21 +++++++++++-------- .../views/purchase_order_import_views.xml | 4 ++-- 3 files changed, 25 insertions(+), 19 deletions(-) diff --git a/custom_purchase_import_wizard/i18n/custom_purchase_import_wizard.pot b/custom_purchase_import_wizard/i18n/custom_purchase_import_wizard.pot index 7dfea14b69..a7ecb4e143 100644 --- a/custom_purchase_import_wizard/i18n/custom_purchase_import_wizard.pot +++ b/custom_purchase_import_wizard/i18n/custom_purchase_import_wizard.pot @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 14.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-08-28 09:35+0000\n" -"PO-Revision-Date: 2023-08-28 09:35+0000\n" +"POT-Creation-Date: 2024-10-22 06:20+0000\n" +"PO-Revision-Date: 2024-10-22 06:20+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -177,6 +177,7 @@ msgstr "" #. module: custom_purchase_import_wizard #: code:addons/custom_purchase_import_wizard/models/purchase_order_import.py:0 +#: code:addons/custom_purchase_import_wizard/models/purchase_order_import.py:0 #, python-format msgid "Error: More than one shipping method found." msgstr "" @@ -211,6 +212,7 @@ msgstr "" #. module: custom_purchase_import_wizard #: code:addons/custom_purchase_import_wizard/models/purchase_order_import.py:0 +#: code:addons/custom_purchase_import_wizard/models/purchase_order_import.py:0 #, python-format msgid "Error: No shipping method found." msgstr "" @@ -355,7 +357,8 @@ msgstr "" #. module: custom_purchase_import_wizard #: model:ir.actions.act_window,name:custom_purchase_import_wizard.purchase_order_import_action -#: model:ir.ui.menu,name:custom_purchase_import_wizard.purchase_order_import_menu +#: model:ir.ui.menu,name:custom_purchase_import_wizard.purchase_order_import_menu_config +#: model:ir.ui.menu,name:custom_purchase_import_wizard.purchase_order_import_menu_purchase msgid "Import Purchase Orders" msgstr "" @@ -451,11 +454,6 @@ msgstr "" msgid "Next Activity Type" msgstr "" -#. module: custom_purchase_import_wizard -#: model:ir.model.fields.selection,name:custom_purchase_import_wizard.selection__purchase_order_import_line__action__nothing -msgid "Nothing" -msgstr "" - #. module: custom_purchase_import_wizard #: model:ir.model.fields,field_description:custom_purchase_import_wizard.field_purchase_order_import__message_needaction_counter msgid "Number of Actions" @@ -577,6 +575,11 @@ msgstr "" msgid "Shipping Method" msgstr "" +#. module: custom_purchase_import_wizard +#: model:ir.model.fields,field_description:custom_purchase_import_wizard.field_purchase_order_import__split_size +msgid "Split Size" +msgstr "" + #. module: custom_purchase_import_wizard #: model:ir.model.fields,field_description:custom_purchase_import_wizard.field_purchase_order_import__state #: model:ir.model.fields,field_description:custom_purchase_import_wizard.field_purchase_order_import_line__state diff --git a/custom_purchase_import_wizard/i18n/es.po b/custom_purchase_import_wizard/i18n/es.po index 8e0ebc1452..6fc97fa87f 100644 --- a/custom_purchase_import_wizard/i18n/es.po +++ b/custom_purchase_import_wizard/i18n/es.po @@ -6,8 +6,8 @@ msgid "" msgstr "" "Project-Id-Version: Odoo Server 14.0\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-08-28 09:36+0000\n" -"PO-Revision-Date: 2023-08-28 09:36+0000\n" +"POT-Creation-Date: 2024-10-22 06:21+0000\n" +"PO-Revision-Date: 2024-10-22 06:21+0000\n" "Last-Translator: \n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -180,6 +180,7 @@ msgstr "" #. module: custom_purchase_import_wizard #: code:addons/custom_purchase_import_wizard/models/purchase_order_import.py:0 +#: code:addons/custom_purchase_import_wizard/models/purchase_order_import.py:0 #, python-format msgid "Error: More than one shipping method found." msgstr "Error: Más de un método de envío encontrado." @@ -203,7 +204,7 @@ msgstr "Error: Se ha encontrado más de un almacén con nombre {}." #: code:addons/custom_purchase_import_wizard/models/purchase_order_import.py:0 #, python-format msgid "Error: No picking type found." -msgstr "Error: No se ha encontrado ningún tipo de operación." +msgstr "Error: Tipo de operación no encontrado." #. module: custom_purchase_import_wizard #: code:addons/custom_purchase_import_wizard/models/purchase_order_import.py:0 @@ -214,6 +215,7 @@ msgstr "Error: Producto no encontrado." #. module: custom_purchase_import_wizard #: code:addons/custom_purchase_import_wizard/models/purchase_order_import.py:0 +#: code:addons/custom_purchase_import_wizard/models/purchase_order_import.py:0 #, python-format msgid "Error: No shipping method found." msgstr "Error: Método de envío no encontrado." @@ -359,7 +361,8 @@ msgstr "Importar líneas de pedido de compra" #. module: custom_purchase_import_wizard #: model:ir.actions.act_window,name:custom_purchase_import_wizard.purchase_order_import_action -#: model:ir.ui.menu,name:custom_purchase_import_wizard.purchase_order_import_menu +#: model:ir.ui.menu,name:custom_purchase_import_wizard.purchase_order_import_menu_config +#: model:ir.ui.menu,name:custom_purchase_import_wizard.purchase_order_import_menu_purchase msgid "Import Purchase Orders" msgstr "Importar pedidos de compra" @@ -455,11 +458,6 @@ msgstr "Resumen de la siguiente actividad" msgid "Next Activity Type" msgstr "Resumen de la siguiente actividad" -#. module: custom_purchase_import_wizard -#: model:ir.model.fields.selection,name:custom_purchase_import_wizard.selection__purchase_order_import_line__action__nothing -msgid "Nothing" -msgstr "Nada" - #. module: custom_purchase_import_wizard #: model:ir.model.fields,field_description:custom_purchase_import_wizard.field_purchase_order_import__message_needaction_counter msgid "Number of Actions" @@ -581,6 +579,11 @@ msgstr "Coste de envío" msgid "Shipping Method" msgstr "Método de envío" +#. module: custom_purchase_import_wizard +#: model:ir.model.fields,field_description:custom_purchase_import_wizard.field_purchase_order_import__split_size +msgid "Split Size" +msgstr "" + #. module: custom_purchase_import_wizard #: model:ir.model.fields,field_description:custom_purchase_import_wizard.field_purchase_order_import__state #: model:ir.model.fields,field_description:custom_purchase_import_wizard.field_purchase_order_import_line__state diff --git a/custom_purchase_import_wizard/views/purchase_order_import_views.xml b/custom_purchase_import_wizard/views/purchase_order_import_views.xml index d9949133a5..ab77b8ce42 100644 --- a/custom_purchase_import_wizard/views/purchase_order_import_views.xml +++ b/custom_purchase_import_wizard/views/purchase_order_import_views.xml @@ -173,14 +173,14 @@ Date: Fri, 18 Oct 2024 11:25:33 +0200 Subject: [PATCH 5/6] [14.0][IMP] custom_breeding_apps: Fields optional hide in tree view. --- custom_breeding_apps/views/stock_move_line_view.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/custom_breeding_apps/views/stock_move_line_view.xml b/custom_breeding_apps/views/stock_move_line_view.xml index c454c1ff4f..b971bdebe9 100644 --- a/custom_breeding_apps/views/stock_move_line_view.xml +++ b/custom_breeding_apps/views/stock_move_line_view.xml @@ -162,7 +162,7 @@ bottom - + Date: Wed, 16 Oct 2024 12:54:10 +0200 Subject: [PATCH 6/6] [ADD] website_payment_acquirer_bank_account --- .../website_payment_acquirer_bank_account | 1 + .../setup.py | 6 + .../README.rst | 73 +++++++++ .../__init__.py | 2 + .../__manifest__.py | 17 ++ .../controllers/__init__.py | 1 + .../controllers/main.py | 129 +++++++++++++++ .../i18n/es.po | 152 ++++++++++++++++++ .../models/__init__.py | 3 + .../models/res_bank_account.py | 10 ++ .../models/res_partner.py | 11 ++ .../models/sale_order.py | 29 ++++ .../static/src/js/choose_bank_account.js | 117 ++++++++++++++ .../views/payment_view.xml | 80 +++++++++ 14 files changed, 631 insertions(+) create mode 120000 setup/website_payment_acquirer_bank_account/odoo/addons/website_payment_acquirer_bank_account create mode 100644 setup/website_payment_acquirer_bank_account/setup.py create mode 100644 website_payment_acquirer_bank_account/README.rst create mode 100644 website_payment_acquirer_bank_account/__init__.py create mode 100644 website_payment_acquirer_bank_account/__manifest__.py create mode 100644 website_payment_acquirer_bank_account/controllers/__init__.py create mode 100644 website_payment_acquirer_bank_account/controllers/main.py create mode 100644 website_payment_acquirer_bank_account/i18n/es.po create mode 100644 website_payment_acquirer_bank_account/models/__init__.py create mode 100644 website_payment_acquirer_bank_account/models/res_bank_account.py create mode 100644 website_payment_acquirer_bank_account/models/res_partner.py create mode 100644 website_payment_acquirer_bank_account/models/sale_order.py create mode 100644 website_payment_acquirer_bank_account/static/src/js/choose_bank_account.js create mode 100644 website_payment_acquirer_bank_account/views/payment_view.xml diff --git a/setup/website_payment_acquirer_bank_account/odoo/addons/website_payment_acquirer_bank_account b/setup/website_payment_acquirer_bank_account/odoo/addons/website_payment_acquirer_bank_account new file mode 120000 index 0000000000..781efd05bb --- /dev/null +++ b/setup/website_payment_acquirer_bank_account/odoo/addons/website_payment_acquirer_bank_account @@ -0,0 +1 @@ +../../../../website_payment_acquirer_bank_account \ No newline at end of file diff --git a/setup/website_payment_acquirer_bank_account/setup.py b/setup/website_payment_acquirer_bank_account/setup.py new file mode 100644 index 0000000000..28c57bb640 --- /dev/null +++ b/setup/website_payment_acquirer_bank_account/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +) diff --git a/website_payment_acquirer_bank_account/README.rst b/website_payment_acquirer_bank_account/README.rst new file mode 100644 index 0000000000..5bce5d67da --- /dev/null +++ b/website_payment_acquirer_bank_account/README.rst @@ -0,0 +1,73 @@ +.. image:: https://img.shields.io/badge/license-LGPL--3-blue.svg + :target: https://opensource.org/licenses/LGPL-3.0 + :alt: License: LGPL-3 + +===================================== +Website Payment Acquirer Bank Account +===================================== + +Overview +======== + +The **Account Payment Mode and Acquirer** module integrates payment modes with bank accounts in sales. It allows users to select a bank account for payments directly from the sales order, enhancing the payment processing workflow. + +Features +======== + +- **Bank Account Selection**: Users can select a bank account for payments directly from the sales order. + +- **Automatic Payment Mode Assignment**: When confirming an order, the payment mode is automatically set based on the selected bank account. + +- **Bank Account Management**: Users can create new bank accounts linked to partners seamlessly. + +Usage +===== + +1. **Install the Module**: + + - Install the module via Odoo's Apps interface. + +2. **Using Bank Accounts**: + + - When creating or editing a sales order, select a bank account from the dropdown. + - Confirm the order, and the payment mode will automatically be assigned based on the selected bank account. + +Configuration +============= + +No additional configuration is required. The module is ready to use once installed. + +Testing +======= + +Test the following scenarios: + +- **Bank Account Selection**: + + - Create or edit a sales order and select a bank account. + - Confirm the order and verify that the payment mode is set correctly. + +- **Bank Account Creation**: + + - Create a new bank account from the sales order and ensure it links correctly to the partner. + +Bug Tracker +=========== + +If you encounter any issues, please report them on the GitHub repository at `GitHub Issues `_. + +Credits +======= + +Contributors +------------ + +* Unai Beristain +* Ana Juaristi + +For module-specific questions, please contact the contributors directly. Support requests should be made through the official channels. + +License +======= + +This project is licensed under the LGPL-3 License. For more details, please refer to the LICENSE file or visit . diff --git a/website_payment_acquirer_bank_account/__init__.py b/website_payment_acquirer_bank_account/__init__.py new file mode 100644 index 0000000000..91c5580fed --- /dev/null +++ b/website_payment_acquirer_bank_account/__init__.py @@ -0,0 +1,2 @@ +from . import controllers +from . import models diff --git a/website_payment_acquirer_bank_account/__manifest__.py b/website_payment_acquirer_bank_account/__manifest__.py new file mode 100644 index 0000000000..7c76cb6836 --- /dev/null +++ b/website_payment_acquirer_bank_account/__manifest__.py @@ -0,0 +1,17 @@ +{ + "name": "Website Payment Acquirer Bank Account", + "version": "14.0.1.0.0", + "author": "Avanzosc", + "summary": "Integrates payment modes with bank accounts in sales.", + "website": "https://github.com/avanzosc/odoo-addons", + "license": "LGPL-3", + "depends": [ + "web", + "sale", + "account", + "payment_acquirer_payment_mode", # trey + ], + "data": ["views/payment_view.xml"], + "installable": True, + "application": False, +} diff --git a/website_payment_acquirer_bank_account/controllers/__init__.py b/website_payment_acquirer_bank_account/controllers/__init__.py new file mode 100644 index 0000000000..12a7e529b6 --- /dev/null +++ b/website_payment_acquirer_bank_account/controllers/__init__.py @@ -0,0 +1 @@ +from . import main diff --git a/website_payment_acquirer_bank_account/controllers/main.py b/website_payment_acquirer_bank_account/controllers/main.py new file mode 100644 index 0000000000..b8e1b72701 --- /dev/null +++ b/website_payment_acquirer_bank_account/controllers/main.py @@ -0,0 +1,129 @@ +import logging + +from odoo import _, http + +_logger = logging.getLogger(__name__) + + +class PaymentController(http.Controller): + @http.route( + "/create_new_bank_account", + type="http", + auth="user", + methods=["POST"], + csrf=False, + website=True, + ) + def create_new_bank_account(self, **kwargs): + new_bank_account = kwargs.get("new_bank_account") + payment_mode_id = kwargs.get("payment_mode_id") + + msg_payment_mode_missing = _("Payment mode ID is missing") + msg_invalid_bank_account = _( + "The bank account number must have exactly 20 digits." + ) + msg_bank_account_exists = _("The bank account already exists") + msg_success = _("Bank account saved successfully") + + if not payment_mode_id: + _logger.warning("Payment mode ID was not provided.") + return http.request.redirect( + f"/shop/payment?message={msg_payment_mode_missing}&status=400" + ) + + payment_mode_id = int(payment_mode_id) + sale_order_id = http.request.session.get("sale_order_id") + + if len(new_bank_account) != 20 or not new_bank_account.isdigit(): + _logger.warning("The bank account number must have exactly 20 digits.") + return http.request.redirect( + f"/shop/payment?message={msg_invalid_bank_account}&status=400" + ) + + existing_bank = ( + http.request.env["res.partner.bank"] + .sudo() + .search([("acc_number", "=", new_bank_account)], limit=1) + ) + + if existing_bank: + _logger.warning("The bank account already exists: %s", new_bank_account) + return http.request.redirect( + f"/shop/payment?message={msg_bank_account_exists}&status=400" + ) + + partner_id = http.request.env.user.partner_id.id + + http.request.env["res.partner.bank"].sudo().create( + { + "acc_number": new_bank_account, + "partner_id": partner_id, + } + ) + + sale_order = http.request.env["sale.order"].sudo().browse(sale_order_id) + sale_order.write( + { + "payment_mode_id": payment_mode_id, + # "bank_account_id": new_bank_account_record.id, + } + ) + + _logger.info( + "Bank account created and successfully assigned to order ID: %s", + sale_order_id, + ) + + return http.request.redirect(f"/shop/payment?message={msg_success}&status=200") + + @http.route( + "/choose_bank_account", + type="json", + auth="user", + methods=["POST"], + csrf=False, + website=True, + ) + def choose_bank_account(self, bank_id=None, **kwargs): + if not bank_id: + _logger.warning("Bank account ID was not provided.") + return { + "status": "error", + "message": "Bank account ID was not provided.", + } + + try: + bank_id = int(bank_id) + except ValueError: + _logger.error("The bank account ID is not a valid number: %s", bank_id) + return { + "status": "error", + "message": "The bank account ID is not a valid number.", + } + + sale_order_id = http.request.session.get("sale_order_id") + if not sale_order_id: + _logger.warning("No sale order ID found in the session.") + return { + "status": "error", + "message": "No sale order ID found in the session.", + } + + sale_order = http.request.env["sale.order"].sudo().browse(sale_order_id) + if not sale_order.exists(): + _logger.warning("No sale order found with ID: %s", sale_order_id) + return { + "status": "error", + "message": "No sale order found with the provided ID.", + } + + # sale_order.write({"bank_account_id": bank_id}) + _logger.info( + "Bank account selected and successfully assigned to order ID: %s", + sale_order_id, + ) + + return { + "status": "success", + "message": "Bank account selected and successfully assigned to the order.", + } diff --git a/website_payment_acquirer_bank_account/i18n/es.po b/website_payment_acquirer_bank_account/i18n/es.po new file mode 100644 index 0000000000..1b5993b6d3 --- /dev/null +++ b/website_payment_acquirer_bank_account/i18n/es.po @@ -0,0 +1,152 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * website_payment_acquirer_bank_account +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 14.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2024-10-17 13:34+0000\n" +"PO-Revision-Date: 2024-10-17 13: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: website_payment_acquirer_bank_account +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_res_bank_account__name +msgid "Account Name" +msgstr "Nombre de la cuenta" + +#. module: website_payment_acquirer_bank_account +#: model:ir.model,name:website_payment_acquirer_bank_account.model_res_bank_account +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_res_bank_account__bank_account +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_sale_order__bank_account_id +msgid "Bank Account" +msgstr "Cuenta bancaria" + +#. module: website_payment_acquirer_bank_account +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_fsm_location__bank_account_ids +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_fsm_person__bank_account_ids +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_res_partner__bank_account_ids +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_res_users__bank_account_ids +msgid "Bank Accounts" +msgstr "Cuentas bancarias" + +#. module: website_payment_acquirer_bank_account +#: code:addons/website_payment_acquirer_bank_account/controllers/main.py:0 +#, python-format +msgid "Bank account saved successfully" +msgstr "Cuenta bancaria guardada con éxito" + +#. module: website_payment_acquirer_bank_account +#: model:ir.model.fields,help:website_payment_acquirer_bank_account.field_sale_order__bank_account_id +msgid "Bank account selected for the payment." +msgstr "Cuenta bancaria seleccionada para el pago." + +#. module: website_payment_acquirer_bank_account +#: model:ir.model,name:website_payment_acquirer_bank_account.model_res_partner +msgid "Contact" +msgstr "Contacto" + +#. module: website_payment_acquirer_bank_account +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_res_bank_account__create_uid +msgid "Created by" +msgstr "Creado por" + +#. module: website_payment_acquirer_bank_account +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_res_bank_account__create_date +msgid "Created on" +msgstr "Creado en" + +#. module: website_payment_acquirer_bank_account +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_res_bank_account__display_name +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_res_partner__display_name +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_sale_order__display_name +msgid "Display Name" +msgstr "Nombre mostrado" + +#. module: website_payment_acquirer_bank_account +#: model_terms:ir.ui.view,arch_db:website_payment_acquirer_bank_account.payment_tokens_list +msgid "Guardar" +msgstr "Guardar" + +#. module: website_payment_acquirer_bank_account +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_res_bank_account__id +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_res_partner__id +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_sale_order__id +msgid "ID" +msgstr "ID" + +#. module: website_payment_acquirer_bank_account +#: model_terms:ir.ui.view,arch_db:website_payment_acquirer_bank_account.payment_tokens_list +msgid "Ingrese una nueva cuenta bancaria (20 dígitos):" +msgstr "Ingrese una nueva cuenta bancaria (20 dígitos):" + +#. module: website_payment_acquirer_bank_account +#: model_terms:ir.ui.view,arch_db:website_payment_acquirer_bank_account.payment_tokens_list +msgid "Introduce 20 dígitos" +msgstr "Introduce 20 dígitos" + +#. module: website_payment_acquirer_bank_account +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_res_bank_account____last_update +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_res_partner____last_update +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_sale_order____last_update +msgid "Last Modified on" +msgstr "Última modificación el" + +#. module: website_payment_acquirer_bank_account +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_res_bank_account__write_uid +msgid "Last Updated by" +msgstr "Última actualización por" + +#. module: website_payment_acquirer_bank_account +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_res_bank_account__write_date +msgid "Last Updated on" +msgstr "Última actualización el" + +#. module: website_payment_acquirer_bank_account +#: model_terms:ir.ui.view,arch_db:website_payment_acquirer_bank_account.payment_tokens_list +msgid "Método de Pago:" +msgstr "Método de Pago:" + +#. module: website_payment_acquirer_bank_account +#: model:ir.model.fields,field_description:website_payment_acquirer_bank_account.field_res_bank_account__partner_id +msgid "Partner" +msgstr "Socio" + +#. module: website_payment_acquirer_bank_account +#: code:addons/website_payment_acquirer_bank_account/controllers/main.py:0 +#, python-format +msgid "Payment mode ID is missing" +msgstr "El ID del modo de pago falta" + +#. module: website_payment_acquirer_bank_account +#: code:addons/website_payment_acquirer_bank_account/models/sale_order.py:0 +#, python-format +msgid "Please select a bank account." +msgstr "Por favor, seleccione una cuenta bancaria." + +#. module: website_payment_acquirer_bank_account +#: model:ir.model,name:website_payment_acquirer_bank_account.model_sale_order +msgid "Sales Order" +msgstr "Pedido de venta" + +#. module: website_payment_acquirer_bank_account +#: model_terms:ir.ui.view,arch_db:website_payment_acquirer_bank_account.payment_tokens_list +msgid "Selecciona una cuenta bancaria existente:" +msgstr "Selecciona una cuenta bancaria existente:" + +#. module: website_payment_acquirer_bank_account +#: code:addons/website_payment_acquirer_bank_account/controllers/main.py:0 +#, python-format +msgid "The bank account already exists" +msgstr "La cuenta bancaria ya existe" + +#. module: website_payment_acquirer_bank_account +#: code:addons/website_payment_acquirer_bank_account/controllers/main.py:0 +#, python-format +msgid "The bank account number must have exactly 20 digits." +msgstr "El número de cuenta bancaria debe tener exactamente 20 dígitos." diff --git a/website_payment_acquirer_bank_account/models/__init__.py b/website_payment_acquirer_bank_account/models/__init__.py new file mode 100644 index 0000000000..ad77877f42 --- /dev/null +++ b/website_payment_acquirer_bank_account/models/__init__.py @@ -0,0 +1,3 @@ +from . import res_bank_account +from . import res_partner +from . import sale_order diff --git a/website_payment_acquirer_bank_account/models/res_bank_account.py b/website_payment_acquirer_bank_account/models/res_bank_account.py new file mode 100644 index 0000000000..0de065f836 --- /dev/null +++ b/website_payment_acquirer_bank_account/models/res_bank_account.py @@ -0,0 +1,10 @@ +from odoo import fields, models + + +class ResBankAccount(models.Model): + _name = "res.bank.account" + _description = "Bank Account" + + name = fields.Char(string="Account Name", required=True) + bank_account = fields.Char(string="Bank Account", required=True) + partner_id = fields.Many2one("res.partner", string="Partner", required=True) diff --git a/website_payment_acquirer_bank_account/models/res_partner.py b/website_payment_acquirer_bank_account/models/res_partner.py new file mode 100644 index 0000000000..e3e84ae644 --- /dev/null +++ b/website_payment_acquirer_bank_account/models/res_partner.py @@ -0,0 +1,11 @@ +from odoo import fields, models + + +class ResPartner(models.Model): + _inherit = "res.partner" + + bank_account_ids = fields.One2many( + "res.bank.account", + "partner_id", + string="Bank Accounts", + ) diff --git a/website_payment_acquirer_bank_account/models/sale_order.py b/website_payment_acquirer_bank_account/models/sale_order.py new file mode 100644 index 0000000000..59cf8dff6b --- /dev/null +++ b/website_payment_acquirer_bank_account/models/sale_order.py @@ -0,0 +1,29 @@ +from odoo import _, fields, models +from odoo.exceptions import ValidationError + + +class SaleOrder(models.Model): + _inherit = "sale.order" + + bank_account_id = fields.Many2one( + "res.bank.account", + string="Bank Account", + help="Bank account selected for the payment.", + ) + + def confirm_order(self): + self.ensure_one() + if self.bank_account_id: + # Si hay una cuenta bancaria seleccionada + self.payment_mode_id = self.bank_account_id.payment_method_id + # Crear la cuenta bancaria si es nueva + if not self.bank_account_id.exists(): + self.env["res.bank.account"].create( + { + "name": self.bank_account_id.name, + "bank_account": self.bank_account_id.bank_account, + "partner_id": self.partner_id.id, + } + ) + else: + raise ValidationError(_("Please select a bank account.")) diff --git a/website_payment_acquirer_bank_account/static/src/js/choose_bank_account.js b/website_payment_acquirer_bank_account/static/src/js/choose_bank_account.js new file mode 100644 index 0000000000..f990560f4c --- /dev/null +++ b/website_payment_acquirer_bank_account/static/src/js/choose_bank_account.js @@ -0,0 +1,117 @@ +odoo.define("website_payment_acquirer_bank_account.choose_bank_account", function ( + require +) { + "use strict"; + + const rpc = require("web.rpc"); + + function getUrlParameter(name) { + const url = new URL(window.location.href); + return url.searchParams.get(name); + } + + function removeUrlParameter(name) { + const url = new URL(window.location.href); + url.searchParams.delete(name); + window.history.replaceState({}, document.title, url); + } + + function displayUrlMessage() { + const message = getUrlParameter("message"); + const status = getUrlParameter("status"); + const messageContainer = document.querySelector("#bank-account-message"); + + if (!messageContainer) { + console.warn("Element with ID 'bank-account-message' not found."); + return; + } + + if (message) { + messageContainer.innerHTML = `
${message}
`; + if (status === "200") { + messageContainer.style.backgroundColor = "#d4edda"; + messageContainer.style.color = "#155724"; + } else if (status === "400") { + messageContainer.style.backgroundColor = "#f8d7da"; + messageContainer.style.color = "#721c24"; + } else { + messageContainer.style.backgroundColor = "#fff3cd"; + messageContainer.style.color = "#856404"; + } + + removeUrlParameter("message"); + removeUrlParameter("status"); + } + } + + function onDOMReady() { + if (document.readyState === "loading") { + document.addEventListener("DOMContentLoaded", function () { + displayUrlMessage(); + }); + } else { + displayUrlMessage(); + } + } + + onDOMReady(); + + function chooseBankAccount(radio) { + if (!radio || !radio.value) { + alert("Please select a bank account."); + return; + } + + const BankID = radio.value; + + const requestData = { + bank_id: BankID, + }; + + const messageContainer = document.querySelector("#bank-account-message"); + if (messageContainer) { + messageContainer.innerHTML = ""; + messageContainer.style.backgroundColor = ""; + } + + rpc + .query({ + route: "/choose_bank_account", + params: requestData, + }) + .then(function (data) { + const messageContainer = document.querySelector("#bank-account-message"); + if (data.status === "success") { + messageContainer.innerHTML = `
${ + data.message || "Bank account selected successfully." + }
`; + messageContainer.style.backgroundColor = "#dff0d8"; + + removeUrlParameter("status"); + } else if (data.status === "error") { + messageContainer.innerHTML = `
${ + data.message || "An error occurred while selecting the bank account." + }
`; + messageContainer.style.backgroundColor = "#f2dede"; + + removeUrlParameter("status"); + } + }) + .catch(function (error) { + console.error("Error:", error); + const messageContainer = document.querySelector("#bank-account-message"); + if (messageContainer) { + messageContainer.innerHTML = `
An error occurred while processing your request.
`; + messageContainer.style.backgroundColor = "#f2dede"; + + removeUrlParameter("status"); + } + }); + } + + window.chooseBankAccount = chooseBankAccount; + + return { + chooseBankAccount: chooseBankAccount, + }; +}); diff --git a/website_payment_acquirer_bank_account/views/payment_view.xml b/website_payment_acquirer_bank_account/views/payment_view.xml new file mode 100644 index 0000000000..33f6604bad --- /dev/null +++ b/website_payment_acquirer_bank_account/views/payment_view.xml @@ -0,0 +1,80 @@ + + +