İçereği Atla
Menü
Bu soru işaretlendi
529 Görünümler

Hello! I am trying to modify a field inside a many2many field, however i am unable to do so. The updates are shown when clicking on edit and changing the wharehouse id, but when click on save the updates disappear.


class sistemas_reabastecimiento_cantidad(models.Model): _inherit = ['advance.procurement.process']
product_ids_replacement = fields.Many2many('product.product', string='Replacement Products', compute='_compute_product_ids_replacement')
@api.depends('warehouse_id') # Add dependencies def _compute_product_ids_replacement(self): for record in self: new_product_ids_replacement = []
for i in record.product_ids: virtual = i.virtual_available print("la virtual es", virtual)
account_ids = self.env['stock.quant'].search([ ('product_id', '=', i.default_code), ('location_id', '=', record.warehouse_id.lot_stock_id.id) ], limit=1) print("las account son,", account_ids)
replacement_product = self.env['product.product'].search([ ('default_code', '=', i.default_code), # Add other relevant search criteria ], limit=1)
if account_ids: valor = self.env['stock.quant'].browse(account_ids.id) i.qty_available = valor.quantity print("la i es",i)
if replacement_product: replacement_product.write({ 'qty_available': valor.quantity, # Update other relevant fields }) new_product_ids_replacement.append(i.id) # Append the original product
else: # Create a new product if not found new_replacement_product = self.env['product.product'].create({ 'name': i.name, 'default_code': i.default_code, 'qty_available': valor.quantity, # Add other relevant fields }) new_product_ids_replacement.append(new_replacement_product.id) else: i.qty_available = 0 new_product_ids_replacement.append(i.id) # Append the original product
# Update the Many2many field record.product_ids_replacement = [(6, 0, new_product_ids_replacement)]

Avatar
Vazgeç