Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata

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
Abbandona
Post correlati Risposte Visualizzazioni Attività
1
gen 20
2781
1
ago 24
5830
2
feb 24
1360
0
mar 15
3458
3
ago 25
1433