In Odoo, updating the value of a One2many field without refreshing the page typically involves using client-side actions with JavaScript. Here's an approach you can take to achieve this functionality:
- Create a Server-Side Method: Define a server-side method that will update the One2many field with the payment information. This method will be called from the client-side.
- Update the One2many Field: Implement the logic in the server-side method to update the One2many field with the payment information.
- Call the Server-Side Method from the Client-Side: Trigger the server-side method using JavaScript when the payment is created. This can be done by sending an RPC (Remote Procedure Call) request to the server.
- Update the View: Once the server-side method has updated the One2many field, update the view on the client-side to reflect the changes without refreshing the page.
Here's an example implementation:
from odoo import models, api
class StockPicking(models.Model):
_inherit = 'stock.picking'
@api.model
def update_payment_information(self, picking_id, payment_data):
picking = self.browse(picking_id)
picking.write({
'account_payment_ids': [(0, 0, payment_data)] # Update One2many field
})
In your JavaScript file or XML template, you can call this server-side method using Odoo's JavaScript framework:
odoo.define('your_module_name.payment_update', function (require) {
"use strict";
var rpc = require('web.rpc');
function updatePaymentInformation(picking_id, payment_data) {
rpc.query({
model: 'stock.picking',
method: 'update_payment_information',
args: [picking_id, payment_data],
}).then(function () {
// Update the view here if necessary
// For example, refresh the One2many field
});
}
// Call this function when payment is created
// Pass picking_id and payment_data as arguments
// For example:
// updatePaymentInformation(picking_id, payment_data);
});
This script should be triggered when the payment is created. It will then call the server-side method update_payment_information, which updates the One2many field in the stock.picking model with the payment information. Finally, the view is updated to reflect the changes without refreshing the page.