Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty

Hello, I have developed a model where it basically does the following:

from odoo import models, fields, api

class StockQuant(models.Model):
_inherit = 'stock.quant'
_description = 'This file stores new data and existing updates to the stock.quant model.'

pza_boxes = fields.Float(
string='Cajas',
compute='_compute_stock_boxes',
help='Conversión del producto de unidades a cajas.',
)

@api.depends('product_id', 'inventory_quantity')
def _compute_stock_boxes(self):
for record in self:
# Obtener la unidad de medida del producto
uom_so_id = record.product_id.uom_so_id

# Verificar si la unidad de medida contiene "Cajas"
if uom_so_id and 'Cajas' in uom_so_id.name:
# Dividir la cantidad disponible por el factor inverso de la unidad de medida
record.pza_boxes = record.inventory_quantity / uom_so_id.factor_inv
else:
# Si no contiene "Cajas", establecer pza_boxes a 0
record.pza_boxes = 0.0

Basically it is a division between the inventory_quantity and factor_inv field where this division will only be executed if there is a unit of measurement that begins with the word "Boxes", and as it is the module is working perfectly, but now I have another problem.

In the product form there are two buttons where it shows you how many units the product has been sold and how many units the product has been purchased (Units sold and units purchased), within the two there is a button called "Measurements" where it shows you different types of options, one of them is the "ordered quantity", how can I apply the same conversion so that the units are displayed but now in boxes?

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
1
tammik. 20
2781
1
elok. 24
5820
2
helmik. 24
1359
0
maalisk. 15
3454
3
elok. 25
1427