Skip to Content
Menu
This question has been flagged

Hi all,

I need to show Forecasted quantity in Purchase Order view.

Tried like this:

get the onhand, qutgoing and incomin qty - create computational field named forecasted_qty and add logic to it, this is the code:

onhand_qty = fields.Float(related='product_id.qty_available', string="Available Stock")
outgoing_qty = fields.Float(related="product_id.outgoing_qty", string="Outgoing Qty")
incoming_qty = fields.Float(related="product_id.incoming_qty", string="Incoming Qty")
forecasted_qty = fields.Float(string="Forecasted", compute='_compute_forecasted_qty')

def _compute_forecasted_qty(self):
    for rec in self:
        self.forecasted_qty = self.onhand_qty - self.outgoing_qty + self.incoming_qty
        rec.forecasted_qty = forecasted_qty


And this is the error:

ValueError: Expected singleton: purchase.order.line(5780, 5781, 5782, 5783)


Can anyone please help me to show forecasted field in Purchase order.


Avatar
Discard
Best Answer

You are calculating from self not from rec, Try the below: 

def _compute_forecasted_qty(self):
    for rec in self:
         rec.forecasted_qty  = rec.onhand_qty - rec.outgoing_qty + rec.incoming_qty

Avatar
Discard
Author

Thank you so much!

Best Answer

Hello Matija, 

You have to also put a one for loop inside the self loop for purchase order line.

Avatar
Discard
Related Posts Replies Views Activity
2
Nov 21
2132
3
Dec 24
2360
1
Jul 24
705
1
Jul 24
2221
1
Jun 24
773