Skip to Content
Menu
This question has been flagged
2 Replies
2194 Views

Hello everyone, I am using odoo 13 community.

I have some calculation regarding delivered quantity of a sale order line for loyalty point of customer. 

I am willing to recalculate every time delivered quantity has changed on sale order line. I have tried several ways like

@api.depends('picking_ids.move_lines')
def onchange_picking(self):
    write some code,

@api.onchange('order_line')

It also don't work.

Can you please suggest me how can I call a function of sale order every time modify on delivered quantity.

Thank you in advance




Avatar
Discard

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]

Best Answer

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.

Avatar
Discard
Author Best Answer

I have solved the issue by inherit stock_picking and check every time status is 'done'. Then recalculate the loyalty point by delivered qty of sale order line

Avatar
Discard
Related Posts Replies Views Activity
4
May 24
10079
1
Apr 24
1566
0
Nov 23
525
1
Sep 23
572
2
Aug 23
2430