[IMP] add posibility to print grouped lines

This commit is contained in:
Iryna Vyshnevska
2022-05-31 01:41:51 +03:00
parent 7a89078b90
commit 66f566f617
2 changed files with 78 additions and 0 deletions

View File

@@ -4,8 +4,11 @@
# Copyright 2016-2022 Tecnativa - Carlos Dauden
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from functools import partial
from odoo import fields, models
from odoo.tools import float_compare
from odoo.tools.misc import formatLang
class StockMoveLine(models.Model):
@@ -78,3 +81,50 @@ class StockMoveLine(models.Model):
"sale_price_total": valued_line.price_total,
}
)
def _get_aggregated_product_quantities(self, **kwargs):
result = super()._get_aggregated_product_quantities(**kwargs)
if self.env.context.get("bypass_modification"):
return result
result = self._get_aggregated_product_quantities_delivery_price(result)
return result
def _get_aggregated_product_quantities_delivery_price(self, aggregated_move_lines):
# sale order can have sold products under different prices
# currently lines on stock.picking will conceder only first price
# so total on sale.order and stock.picking will differ
# consider riding of aggregating of lines for stock.picking
fmt = partial(
formatLang,
self.with_context(lang=self.picking_id.partner_id.lang).env,
currency_obj=self.picking_id.currency_id,
)
for line in aggregated_move_lines:
product = aggregated_move_lines[line]["product"]
uom = aggregated_move_lines[line]["product_uom"]
sml = self._find_sml(product, uom)
qty = aggregated_move_lines[line]["qty_done"] or sml.move_id.product_uom_qty
aggregated_move_lines[line].update(
{
"unit_price": fmt(sml.sale_price_unit),
"tax": ", ".join(
map(
lambda x: (x.description or x.name),
sml.sale_tax_id,
)
),
"total": (sml.sale_price_unit * qty),
}
)
return aggregated_move_lines
def _find_sml(self, product, uom_name):
line = fields.first(
self.filtered(
lambda sml: sml.product_id == product
and sml.product_uom_id.name == uom_name
)
)
return line

View File

@@ -125,4 +125,32 @@
</xpath>
</template>
<template id="aggregated_move_lines_price_part">
<td class="text-right" name="move_line_aggregated_price">
<span t-esc="aggregated_lines[line]['unit_price']" />
</td>
<td class="text-right" name="move_line_aggregated_taxl">
<span t-esc="aggregated_lines[line]['tax']" />
</td>
<td class="text-right" name="move_line_aggregated_total">
<span
t-esc="aggregated_lines[line]['total']"
t-options='{"widget": "monetary", "display_currency": o.currency_id}'
/>
</td>
</template>
<template
id="stock_report_delivery_aggregated_move_lines"
inherit_id="stock.stock_report_delivery_aggregated_move_lines"
>
<xpath expr="//td[last()]" position="after">
<t t-if="o.picking_type_id.code == 'outgoing'">
<t
t-call="stock_picking_report_valued.aggregated_move_lines_price_part"
/>
</t>
</xpath>
</template>
</odoo>