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

Hi,

I am developing with odoo14 and has this problem.

We sell food with expiry date which we used to store as serial no in YYYYMMDD format.

When we place a PO, we are told the expiry date of a product in a future shipment. I call it expected_serial_no. I extended purchase.order.line model and added a field expected_serial_no to store it as below.


class hago_purchase_order_line(models.Model):
_name = 'purchase.order.line'
_inherit = 'purchase.order.line'

'''Expected BBD when receiving a product. Help to make sure the actual BBD that we receive is the same as the expected BBD.'''
expected_serial_no = fields.Char(string='Exp Serial No', default='')

-----------------

When I received a shipment, I would like to call the expected_serial_no from the purchase_order_line above and put in the order line of stock.move.operations.form so that when the user register the actual received expiry date of the goods, he can see whether it is the same as the expected expiry date.

I tried to extend stock.move.line model and add in a computed field as below and try to display this field in the stock.move.operations.form as a field in the order line but it does not work. 

class hago_stock_move_line(models.Model):
_name = 'stock.move.line'
_inherit = 'stock.move.line'

'''Expected BBD when receiving a product. No need to store this. Just look it up from the purchase_order_line.'''
expected_serial_no = fields.Char(string='Exp Serial No', compute='_get_exp_serial_no')

def _get_exp_serial_no(self):
if self.move_id:
exp_serial_no = self.move_id.purchase_line_id.expected_serial_no
self.expected_serial_no = exp_serial_no

I put a breakpoint in the above code but it did not stop at the breakpoints. I doubt that the above code is called.


How do I get back the expected_serial_no from the purchase_order_line and put it into stock.move.operations.form.

Please help!!!

Regards,
Simon


Avatar
Discard
Author Best Answer

Thank you for the answer. However, purchase_line_id does not seems to exist in stock_move model in odoo 14. It used to have this field in earlier version. How can I trace back to the purchase_line that stored the expected_serial_no from stock_move_line. Please advise. Thanks.

Simon

Avatar
Discard
Best Answer

you may need to decorate the compute function with @api.depend('move_id',...)

you may also use related='movie_id.purchase_line_id.expected_serial_no', rather than computed field

Avatar
Discard