I need to calculate product qty as below.
Product A unit of measure is "Cotton 48" (Cotton 48 = 48 Units)
I want to sell 32'Cotton 48' and 5 Units.
I want to create 2 new fields in sale.order.line (Cotton Qty, Unit Qty).
The user will put 2 in cotton qty and 5 in Unit Qty.
Then product_uom_qty should calculate in unit qty ((cotton qty: 48 x 2 = 96 + Unit Qty: 5) = 101)
Any help on this issue. I want to use same method in pos.order.line too.
Edit: Here is my model.py file for sale.order.line
from odoo import api, fields, models, _
import odoo.addons.decimal_precision as dp
from odoo.exceptions import ValidationError
class SaleOrder(models.Model):
_inherit = "sale.order"
@api.depends('order_line.product_uom_qty')
def _qty_all(self):
vals = {}
for line in self.mapped('order_line').filtered(
lambda l: l.product_uom_qty):
vals[line] = {
'product_uom_qty': line.product_uom_qty,
}
product_uom_qty = line.cotton_qty * line.product_uom.factor_inv + line.pcs_qty
line.update({
'product_uom_qty': product_uom_qty,
})
res = super(SaleOrder, self)._qty_all()
for line in vals.keys():
line.update(vals[line])
return res
class SaleOrderLine(models.Model):
_inherit = "sale.order.line"
cotton_qty = fields.Float(
string="Cotton Qty",
digits=dp.get_precision('Qty'),
help="Cotton Quantity.")
pcs_qty = fields.Float(
string="Unit Qty",
digits=dp.get_precision('Qty'),
help="Unit Quantity.")
@api.depends('product_uom_qty')
def _final_qty(self):
vals = {}
for line in self.filtered(lambda l: l.product_uom_qty):
vals[line] = {
'cotton_qty': line.cotton_qty,
'pcs_qty': line.pcs_qty,
}
product_uom_qty = ccotton_qty * product_uom.factor_inv + line.pcs_qty
line.update({
'product_uom_qty': product_uom_qty,
})
res = super(SaleOrderLine, self)._final_qty()
for line in vals.keys():
line.update(vals[line])
return res
Please add piece of code you developer of any compute method or something . It will be more easy to understand your question
@Nitin Question updated with a code.