[FIX] sale_stock_usability: fix order of lines in report method
This commit is contained in:
@@ -23,58 +23,60 @@ class StockPicking(models.Model):
|
|||||||
total_amount = 0.0
|
total_amount = 0.0
|
||||||
total_weight_kg = 0.0
|
total_weight_kg = 0.0
|
||||||
lines = []
|
lines = []
|
||||||
for line in self.move_line_ids:
|
# loop on stock.move AND THEN on stock.move.line to keep the order
|
||||||
move = line.move_id
|
# of the sale order lines
|
||||||
uom = line.product_uom_id
|
for move in self.move_ids:
|
||||||
if uom.category_id.id == weight_uom_categ_id:
|
for line in move.move_line_ids:
|
||||||
weight_kg_subtotal = uom._compute_quantity(line.qty_done, kg_uom)
|
uom = line.product_uom_id
|
||||||
else:
|
if uom.category_id.id == weight_uom_categ_id:
|
||||||
qty_product_uom = uom._compute_quantity(line.qty_done, line.product_id.uom_id)
|
weight_kg_subtotal = uom._compute_quantity(line.qty_done, kg_uom)
|
||||||
weight_kg_subtotal = qty_product_uom * line.product_id.weight
|
else:
|
||||||
if (
|
qty_product_uom = uom._compute_quantity(line.qty_done, line.product_id.uom_id)
|
||||||
move.sale_line_id and
|
weight_kg_subtotal = qty_product_uom * line.product_id.weight
|
||||||
move.sale_line_id.product_id == line.product_id and
|
if (
|
||||||
move.sale_line_id.product_uom_qty > 0 and
|
move.sale_line_id and
|
||||||
move.sale_line_id.product_uom == uom):
|
move.sale_line_id.product_id == line.product_id and
|
||||||
price_unit = currency.round(
|
move.sale_line_id.product_uom_qty > 0 and
|
||||||
line.move_id.sale_line_id.price_subtotal / move.sale_line_id.product_uom_qty)
|
move.sale_line_id.product_uom == uom):
|
||||||
logger.info(
|
price_unit = currency.round(
|
||||||
'For move line %s, got price %s from sale order line',
|
line.move_id.sale_line_id.price_subtotal / move.sale_line_id.product_uom_qty)
|
||||||
line.display_name, price_unit)
|
logger.info(
|
||||||
else:
|
'For move line %s, got price %s from sale order line',
|
||||||
# TODO remove tax if tax included
|
line.display_name, price_unit)
|
||||||
price_unit = partner_pricelist._get_product_price(
|
else:
|
||||||
line.product_id, line.qty_done, uom=uom,
|
# TODO remove tax if tax included
|
||||||
date=fields.Date.to_date(self.date_done))
|
price_unit = partner_pricelist._get_product_price(
|
||||||
price_unit = currency.round(price_unit)
|
line.product_id, line.qty_done, uom=uom,
|
||||||
# Only for very special case where picking is linked to sale order but this line
|
date=fields.Date.to_date(self.date_done))
|
||||||
# is from linked to sale order line, and the partner pricelist is NOT in the same
|
price_unit = currency.round(price_unit)
|
||||||
# currency as the sale order pricelist. Should very rarely happen.
|
# Only for very special case where picking is linked to sale order but this line
|
||||||
if currency != partner_pricelist.currency_id:
|
# is from linked to sale order line, and the partner pricelist is NOT in the same
|
||||||
raise UserError(_(
|
# currency as the sale order pricelist. Should very rarely happen.
|
||||||
"The pricelist of the related sale order is in currency "
|
if currency != partner_pricelist.currency_id:
|
||||||
"%(sale_pricelist_currency)s whereas the pricelist "
|
raise UserError(_(
|
||||||
"%(partner_pricelist_name)s of partner %(partner)s "
|
"The pricelist of the related sale order is in currency "
|
||||||
"is in currency %(partner_pricelist_currency)s.",
|
"%(sale_pricelist_currency)s whereas the pricelist "
|
||||||
sale_pricelist_currency=self.sale_id.currency_id.name,
|
"%(partner_pricelist_name)s of partner %(partner)s "
|
||||||
partner_pricelist_name=partner_pricelist.name,
|
"is in currency %(partner_pricelist_currency)s.",
|
||||||
partner=self.partner_id.display_name,
|
sale_pricelist_currency=self.sale_id.currency_id.name,
|
||||||
partner_pricelist_currency=partner_pricelist.currency_id.name))
|
partner_pricelist_name=partner_pricelist.name,
|
||||||
logger.info(
|
partner=self.partner_id.display_name,
|
||||||
'For move line %s, got price %s from partner pricelist %s',
|
partner_pricelist_currency=partner_pricelist.currency_id.name))
|
||||||
line.display_name, price_unit, partner_pricelist.display_name)
|
logger.info(
|
||||||
price_subtotal = currency.round(price_unit * line.qty_done)
|
'For move line %s, got price %s from partner pricelist %s',
|
||||||
total_amount += price_subtotal
|
line.display_name, price_unit, partner_pricelist.display_name)
|
||||||
lines.append({
|
price_subtotal = currency.round(price_unit * line.qty_done)
|
||||||
'line': line,
|
total_amount += price_subtotal
|
||||||
'qty': line.qty_done,
|
lines.append({
|
||||||
'uom': uom,
|
'line': line,
|
||||||
'product': line.product_id,
|
'qty': line.qty_done,
|
||||||
'weight_kg_subtotal': weight_kg_subtotal,
|
'uom': uom,
|
||||||
'price_unit': price_unit,
|
'product': line.product_id,
|
||||||
'price_subtotal': price_subtotal,
|
'weight_kg_subtotal': weight_kg_subtotal,
|
||||||
'lot': line.lot_id and line.lot_id.display_name or (line.lot_name or ''),
|
'price_unit': price_unit,
|
||||||
})
|
'price_subtotal': price_subtotal,
|
||||||
|
'lot': line.lot_id and line.lot_id.display_name or (line.lot_name or ''),
|
||||||
|
})
|
||||||
res = {
|
res = {
|
||||||
'lines': lines,
|
'lines': lines,
|
||||||
'currency': currency,
|
'currency': currency,
|
||||||
|
|||||||
Reference in New Issue
Block a user