In Odoo 13, you can use the "picking_ids" field in the sale order line to trigger an onchange event when the delivery slips for the order line are modified. To do this, you can use the following code:
from odoo import api, fields, models
class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
picking_ids = fields.Many2many('stock.picking', 'sale_order_picking_rel', 'order_line_id', 'picking_id',
string='Picking List')
@api.onchange('picking_ids')
def onchange_picking(self):
# Write your code here to recalculate the loyalty points based on the updated delivery slips
pass
In this code, the "picking_ids" field is defined in the sale order line model, and the "onchange_picking" method is decorated with the "@api.onchange('picking_ids')" decorator. This will cause the "onchange_picking" method to be called whenever the delivery slips for the order line are modified.
In the "onchange_picking" method, you can write the code to recalculate the loyalty points for the customer based on the updated delivery slips. For example, you can use the "picking_ids" field to access the delivery slips for the order line, and then use the "move_lines" field in the stock picking model to access the details of the products that were delivered.
Once you have written the code to recalculate the loyalty points in the "onchange_picking" method, you can save the changes and test the onchange event in your Odoo instance. When you modify the delivery slips for a sale order line, the "onchange_picking" method should be called and the loyalty points should be updated accordingly.
In summary, to trigger an onchange event when the delivery slips for a sale order line are modified in Odoo 13, you can use the "picking_ids" field and the "@api.onchange('picking_ids')" decorator in the sale order line model. This will allow you to write the code to recalculate the loyalty points based on the updated delivery slips, and ensure that the loyalty points are updated whenever the delivery slips are modified.
qty_delivered is a compute field. Try override the compute function or create a new field with same dependencies as that of qty_delivered [As per your requirement]