+
+
+ purchase.order
+
+
+
+
+
+
+
+
+
+
+
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):
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
diff --git a/website_payment_acquirer_bank_account/controllers/main.py b/website_payment_acquirer_bank_account/controllers/main.py
index b8e1b72701..4f32dbac09 100644
--- a/website_payment_acquirer_bank_account/controllers/main.py
+++ b/website_payment_acquirer_bank_account/controllers/main.py
@@ -20,7 +20,7 @@ def create_new_bank_account(self, **kwargs):
msg_payment_mode_missing = _("Payment mode ID is missing")
msg_invalid_bank_account = _(
- "The bank account number must have exactly 20 digits."
+ "The bank account number must start with 'ES' followed by 22 digits."
)
msg_bank_account_exists = _("The bank account already exists")
msg_success = _("Bank account saved successfully")
@@ -31,11 +31,18 @@ def create_new_bank_account(self, **kwargs):
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.")
+ # Convert the bank account to uppercase
+ new_bank_account = new_bank_account.upper()
+
+ # Validate that the bank account starts with 'ES' and is followed by exactly 22 digits
+ if not (
+ new_bank_account.startswith("ES")
+ and len(new_bank_account) == 24
+ and new_bank_account[2:].isdigit()
+ ):
+ _logger.warning(
+ "The bank account must start with 'ES' followed by 22 digits."
+ )
return http.request.redirect(
f"/shop/payment?message={msg_invalid_bank_account}&status=400"
)
@@ -54,23 +61,52 @@ def create_new_bank_account(self, **kwargs):
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,
- }
+ # Remove any existing bank accounts for this partner
+ http.request.env["res.partner.bank"].sudo().search(
+ [("partner_id", "=", partner_id)]
+ ).unlink()
+
+ # Create the new bank account
+ new_bank_account_record = (
+ 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,
- }
+ # Retrieve the sale_order_id from the session
+ sale_order_id = (
+ kwargs.get("sale_order_id")
+ or http.request.session.get("sale_order_id")
+ or http.request.env["website"].sudo().sale_get_order()
)
+ if not sale_order_id:
+ _logger.warning("Sale order ID was not provided.")
+ return http.request.redirect(
+ f"/shop/payment?message=Sale order ID missing&status=400"
+ )
+
+ sale_order = http.request.env["sale.order"].sudo().browse(sale_order_id)
+ if not sale_order.exists():
+ _logger.warning("Sale order not found: %s", sale_order_id)
+ return http.request.redirect(
+ f"/shop/payment?message=Sale order not found&status=400"
+ )
+
+ if sale_order and payment_mode_id:
+ sale_order.write(
+ {
+ "payment_mode_id": int(payment_mode_id),
+ }
+ )
_logger.info(
- "Bank account created and successfully assigned to order ID: %s",
+ "New bank account created and old ones removed for partner ID: %s. Assigned to order ID: %s",
+ partner_id,
sale_order_id,
)
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
index f990560f4c..a4e5517e4c 100644
--- 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
@@ -5,18 +5,23 @@ odoo.define("website_payment_acquirer_bank_account.choose_bank_account", functio
const rpc = require("web.rpc");
+ let isPaymentButtonDisabled = true; // Variable to track the disabled state of the payment button
+
function getUrlParameter(name) {
+ console.log(`Getting URL parameter: ${name}`);
const url = new URL(window.location.href);
return url.searchParams.get(name);
}
function removeUrlParameter(name) {
+ console.log(`Removing URL parameter: ${name}`);
const url = new URL(window.location.href);
url.searchParams.delete(name);
window.history.replaceState({}, document.title, url);
}
function displayUrlMessage() {
+ console.log("Displaying URL message");
const message = getUrlParameter("message");
const status = getUrlParameter("status");
const messageContainer = document.querySelector("#bank-account-message");
@@ -27,6 +32,7 @@ odoo.define("website_payment_acquirer_bank_account.choose_bank_account", functio
}
if (message) {
+ console.log(`Message found: ${message}, Status: ${status}`);
messageContainer.innerHTML = `${message}
`;
if (status === "200") {
messageContainer.style.backgroundColor = "#d4edda";
@@ -41,28 +47,39 @@ odoo.define("website_payment_acquirer_bank_account.choose_bank_account", functio
removeUrlParameter("message");
removeUrlParameter("status");
+ } else {
+ console.log("No message to display");
}
}
function onDOMReady() {
- if (document.readyState === "loading") {
- document.addEventListener("DOMContentLoaded", function () {
- displayUrlMessage();
- });
- } else {
- displayUrlMessage();
- }
+ console.log("Document is ready");
+ displayUrlMessage();
+ handleBankAccountSelect();
+ updatePaymentButtonState();
+ startMonitoringPaymentButton(); // Start monitoring the payment button state
}
- onDOMReady();
+ function startMonitoringPaymentButton() {
+ setInterval(() => {
+ console.log("Checking payment button state");
+ const paymentButton = document.getElementById("o_payment_form_pay");
+ if (paymentButton) {
+ const shouldBeDisabled = isPaymentButtonDisabled; // Get the desired state from the variable
+ paymentButton.disabled = shouldBeDisabled; // Set the button's disabled state
+ }
+ }, 20);
+ }
function chooseBankAccount(radio) {
if (!radio || !radio.value) {
+ console.log("No bank account selected.");
alert("Please select a bank account.");
return;
}
const BankID = radio.value;
+ console.log(`Choosing bank account with ID: ${BankID}`);
const requestData = {
bank_id: BankID,
@@ -80,25 +97,26 @@ odoo.define("website_payment_acquirer_bank_account.choose_bank_account", functio
params: requestData,
})
.then(function (data) {
+ console.log("RPC response received:", data);
const messageContainer = document.querySelector("#bank-account-message");
if (data.status === "success") {
- messageContainer.innerHTML = `${
- data.message || "Bank account selected successfully."
- }
`;
+ messageContainer.innerHTML = `${data.message || "Bank account selected successfully."
+ }
`;
messageContainer.style.backgroundColor = "#dff0d8";
+ console.log("Bank account selected successfully");
removeUrlParameter("status");
} else if (data.status === "error") {
- messageContainer.innerHTML = `${
- data.message || "An error occurred while selecting the bank account."
- }
`;
+ messageContainer.innerHTML = `${data.message || "An error occurred while selecting the bank account."
+ }
`;
messageContainer.style.backgroundColor = "#f2dede";
+ console.log("Error selecting bank account:", data.message);
removeUrlParameter("status");
}
})
.catch(function (error) {
- console.error("Error:", error);
+ console.error("Error during RPC call:", error);
const messageContainer = document.querySelector("#bank-account-message");
if (messageContainer) {
messageContainer.innerHTML = `An error occurred while processing your request.
`;
@@ -109,7 +127,73 @@ odoo.define("website_payment_acquirer_bank_account.choose_bank_account", functio
});
}
+ function handleBankAccountSelect() {
+ console.log("Handling bank account selection");
+ const radioButtons = document.querySelectorAll(
+ 'input[type="radio"][data-acquirer-id="25"]'
+ );
+ const ibanFormDiv = document.getElementById("bank-account-select-iban-form");
+ const formRadioButtons = document.querySelectorAll(
+ 'form[action="/choose_bank_account"] input[type="radio"]'
+ );
+ const paymentButton = document.getElementById("o_payment_form_pay");
+
+ updatePaymentButtonState();
+
+ radioButtons.forEach(function (radio) {
+ radio.addEventListener("change", function () {
+ console.log(`Radio button changed: ${radio.value}`);
+ if (radio.checked) {
+ console.log(`Radio button ${radio.value} is selected.`);
+ if (formRadioButtons.length > 0) {
+ formRadioButtons[0].checked = true;
+ chooseBankAccount(formRadioButtons[0]);
+ }
+ }
+
+ if (!radio.checked && ibanFormDiv) {
+ ibanFormDiv.style.display = "none";
+ console.log("IBAN form div removed");
+ } else if (radio.checked && ibanFormDiv) {
+ ibanFormDiv.style.display = ""; // Eliminar el estilo de display
+ }
+
+ updatePaymentButtonState();
+ });
+ if (!radio.checked && ibanFormDiv) {
+ ibanFormDiv.style.display = "none";
+ console.log("IBAN form div removed");
+ } else if (radio.checked && ibanFormDiv) {
+ ibanFormDiv.style.display = ""; // Eliminar el estilo de display
+ }
+ });
+
+ formRadioButtons.forEach(function (radio) {
+ radio.addEventListener("change", updatePaymentButtonState);
+ });
+ }
+
+ function updatePaymentButtonState() {
+ console.log("Updating payment button state");
+ const formRadioButtons = document.querySelectorAll(
+ 'form[action="/choose_bank_account"] input[type="radio"]'
+ );
+ const paymentButton = document.getElementById("o_payment_form_pay");
+ const anySelected = Array.from(formRadioButtons).some((radio) => radio.checked);
+
+ if (anySelected) {
+ console.log("At least one radio button is selected. Enabling payment button.");
+ isPaymentButtonDisabled = false; // Update variable state
+ } else {
+ console.log("No radio buttons are selected. Disabling payment button.");
+ isPaymentButtonDisabled = true; // Update variable state
+ }
+ }
+ console.log("Definición de onDOMReady:", typeof onDOMReady);
+ document.addEventListener("DOMContentLoaded", onDOMReady);
+
window.chooseBankAccount = chooseBankAccount;
+ onDOMReady(); // Llamada manual para verificar que la función funcione
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
index 33f6604bad..dbc9a1303b 100644
--- a/website_payment_acquirer_bank_account/views/payment_view.xml
+++ b/website_payment_acquirer_bank_account/views/payment_view.xml
@@ -19,7 +19,7 @@
-
+