Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
2 Trả lời
1120 Lượt xem

Dear all

My codes are, how to write this inverse function so the user can edit the field 'lot_ids'. thanks


lot_ids = fields.Many2many('stock.lot', string='Lots/Serials', compute='_get_lot_name',
readonly=False, domain="[('product_id', '=', product_id)]", store=True)
lot_name = fields.Char(string='Lots/Serials', compute='_get_lot_name', readonly=False, store=True)
has_lot_id = fields.Boolean(string='Has Lot ids', compute="_compute_has_lot_id", store=True)
@api.depends('has_lot_id', 'picking_id','picking_id.move_line_ids')
def _get_lot_name(self):
for rec in self:
if rec.has_lot_id and rec.picking_id:
stock_move_lines = self.env['stock.move.line'].sudo().search([('picking_id', '=', rec.picking_id.id)])
# print('stock_move_lines', stock_move_lines, stock_move_lines.mapped('lot_id'),
# stock_move_lines.mapped('lot_name'))
if all(value is not False for value in stock_move_lines.mapped('lot_name')):
# Get the lot names from the stock move lines, filtering out any non-string values (e.g.,False)
# print('stock_move_lines.mapped name', stock_move_lines.mapped('lot_name'))
lot_names = [name for name in stock_move_lines.mapped('lot_name') if isinstance(name, str)]
rec.lot_name = ', '.join(lot_names) if lot_names else ''
elif len(stock_move_lines.mapped('lot_id').mapped('id')):
# print('stock_move_lines.mapped', stock_move_lines.mapped('lot_id').mapped('id'))
lot_ids = stock_move_lines.mapped('lot_id').ids
rec.lot_ids = self.env['stock.lot'].browse(lot_ids)







Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,
In the inverse function you have to set the reverse logic you have added inside the compute function. For reference have a look at this video:  How To Set Inverse Function For Computed Field In Odoo


Thanks

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hi,

To write an inverse function for a computed field in Odoo 17, refer to the blog How to add inverse function for compute fields.


The blog provides a detailed example of how to define and implement such an inverse function.


Hopes it helps.

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
4
thg 5 25
2591
2
thg 5 25
5985
1
thg 3 25
1722
4
thg 3 25
4584
3
thg 2 25
5593