Skip to Content
Meniu
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
Această întrebare a fost marcată
1 Răspunde
4690 Vizualizări

We have a custom picking operations report that shows the location the product is coming from. 


From studio the Esc expression is ml( Stock Move) -> Move Line -> From -> Display Name.


This works perfectly fine if the product is only coming from one location, however creates an error if the product has multiple locations. 


How can I update the report to handle these cases?

Imagine profil
Abandonează
Cel mai bun răspuns

Hi,

You may be receiving single ton error in this case, it will be nice, if you could have shared the corresponding code entries generated by studio.

Activate developer mode and navigate to View menu under Settings -> Technical and see if you can spot the inherited view created by studio application here.

In your case, suppose if you have code like move_ids_without_package.name , you just need to change it to  ', '.join(move_ids_without_package.mapped('display_name'))

Thanks

Imagine profil
Abandonează
Autor

Hi Niyas,

Here is the code:

<t t-name="stock.report_picking_copy_1">
<t t-call="web.html_container">
<t t-foreach="docs" t-as="o">
<t t-call="web.external_layout">
<div class="page">
<div class="row justify-content-end mb16">
<div class="col-4" name="right_box">
<div t-field="o.name" t-options="{'widget': 'barcode', 'width': 600, 'height': 100, 'img_style': 'width:300px;height:50px;'}"/></div>
</div>
<div class="row">
<div class="col-6" name="div_outgoing_address">
<div t-if="o.move_ids_without_package and o.move_ids_without_package[0].partner_id and o.move_ids_without_package[0].partner_id.id != o.partner_id.id">
<span>
<strong>Delivery Address:</strong>
</span>
<div t-field="o.move_ids_without_package[0].partner_id" t-options="{&quot;widget&quot;: &quot;contact&quot;, &quot;fields&quot;: [&quot;address&quot;, &quot;name&quot;, &quot;phone&quot;], &quot;no_marker&quot;: True, &quot;phone_icons&quot;: True}"/></div>
<div t-if="o.picking_type_id.code != 'internal' and (not o.move_ids_without_package or not o.move_ids_without_package[0].partner_id) and o.picking_type_id.warehouse_id.partner_id">
<span>
<strong>Warehouse Address:</strong>
</span>
<div t-field="o.picking_type_id.warehouse_id.partner_id" t-options="{&quot;widget&quot;: &quot;contact&quot;, &quot;fields&quot;: [&quot;address&quot;, &quot;name&quot;, &quot;phone&quot;], &quot;no_marker&quot;: True, &quot;phone_icons&quot;: True}"/></div>
</div>
<div class="col-5 offset-1" name="div_incoming_address">
<div t-if="o.picking_type_id.code=='incoming' and o.partner_id">
<span>
<strong>Vendor Address:</strong>
</span>
</div>
<div t-if="o.picking_type_id.code=='internal' and o.partner_id">
<span>
<strong>Warehouse Address:</strong>
</span>
</div>
<div t-if="o.picking_type_id.code=='outgoing' and o.partner_id">
<span>
<strong>Customer Address:</strong>
</span>
</div>
<div t-if="o.partner_id" name="partner_header">
<div t-field="o.partner_id" t-options="{&quot;widget&quot;: &quot;contact&quot;, &quot;fields&quot;: [&quot;address&quot;, &quot;name&quot;, &quot;phone&quot;, &quot;vat&quot;], &quot;no_marker&quot;: True, &quot;phone_icons&quot;: True}"/></div>
</div>
</div>
<br/>
<h1 t-field="o.name" class="mt0 float-start"/>
<div class="row mt48 mb32">
<div t-if="o.origin" class="col-auto" name="div_origin">
<strong>Order:</strong>
<p t-field="o.origin"/>
</div>
<div class="col-auto" name="div_state">
<strong>Status:</strong>
<p t-field="o.state"/>
</div>
<div class="col-auto" name="div_sched_date">
<strong>Scheduled Date:</strong>
<p t-field="o.scheduled_date"/>
</div>
</div>
<table class="table table-sm" t-if="o.move_ids_without_package">
<thead>
<tr>
<th name="th_product">
<strong>Description</strong>
</th>
<th>
<strong>Quantity</strong>
</th>
<th>
<strong>Reserved</strong>
</th>
<th name="th_from" t-if="o.picking_type_id.code != 'incoming'" align="left" groups="stock.group_stock_multi_locations">
<strong>From</strong>
</th>
<th name="th_to" t-if="o.picking_type_id.code != 'outgoing'" groups="stock.group_stock_multi_locations">
<strong>To</strong>
</th>
<th name="th_serial_number" class="text-center" t-if="has_serial_number">
<strong>Lot/Serial Number</strong>
</th>
<th name="th_barcode" class="text-center">
<strong>Product Barcode</strong>
</th>
</tr>
</thead>
<tbody>
<t t-foreach="o.move_ids_without_package" t-as="ml">
<tr>
<td>
<span t-field="ml.sale_line_id.name"/>
<br/>
<span t-field="ml.product_id.description_picking"/>
</td>
<td>
<span t-field="ml.product_uom_qty"/>
<span t-field="ml.product_uom" groups="uom.group_uom"/>
</td>
<td>
<span t-field="ml.reserved_availability"/>
<span t-field="ml.product_uom" groups="uom.group_uom"/>
</td>
<td t-if="o.picking_type_id.code != 'incoming'" groups="stock.group_stock_multi_locations">
<span t-esc="ml.move_line_ids.location_id.display_name"/>
</td>
<td t-if="o.picking_type_id.code != 'outgoing'" groups="stock.group_stock_multi_locations">
<div>
<span t-field="ml.location_dest_id"/>
</div>
</td>
<td class=" text-center h6" t-if="has_serial_number">
<div t-if="has_serial_number and (ml.lot_id or ml.lot_name)" t-esc="ml.lot_id.name or ml.lot_name" t-options="{'widget': 'barcode', 'humanreadable': 1, 'width': 400, 'height': 100, 'img_style': 'width:100%;height:35px;'}"/>
</td>
<td class="text-center">
<span t-if="ml.product_id and ml.product_id.barcode">
<div t-field="ml.product_id.barcode" t-options="{'widget': 'barcode', 'symbology': 'auto', 'width': 400, 'height': 100, 'quiet': 0, 'img_style': 'height:35px;'}"/>
</span>
<t t-set="product_barcode" t-value="ml.product_id.barcode"/>
</td>
</tr>
</t>
</tbody>
</table>
<div class="row"/>
<div class="row">
<div class="col">
<span>
<p style="margin-bottom: 0px;">Notes:</p>
</span>
</div>
</div>
<div class="row">
<div class="col">
<span t-field="o.sale_id.x_studio_text_field_wIJPE"/>
</div>
</div>
<!--
<table class="table table-sm" t-if="o.move_line_ids and o.move_ids_without_package"><t t-set="has_barcode" t-value="any(move_line.product_id and move_line.product_id.sudo().barcode or move_line.package_id for move_line in o.move_line_ids)"/><t t-set="has_serial_number" t-value="any(move_line.lot_id or move_line.lot_name for move_line in o.move_line_ids)" groups="stock.group_production_lot"/><thead><tr><th name="th_product"><strong>Product</strong></th><th><strong>Quantity</strong></th><th name="th_from" t-if="o.picking_type_id.code != 'incoming'" align="left" groups="stock.group_stock_multi_locations"><strong>From</strong></th><th name="th_to" t-if="o.picking_type_id.code != 'outgoing'" groups="stock.group_stock_multi_locations"><strong>To</strong></th><th name="th_serial_number" class="text-center" t-if="has_serial_number"><strong>Lot/Serial Number</strong></th><th name="th_barcode" class="text-center" t-if="has_barcode"><strong>Product Barcode</strong></th></tr></thead><tbody>
-->
<!-- In case you come across duplicated lines, ask NIM or LAP -->
<!--
<t t-foreach="o.move_line_ids_without_package" t-as="ml"><tr><td><span t-field="ml.product_id.display_name"/><br/><span t-field="ml.product_id.description_picking"/></td><td><span t-if="o.state != 'done'" t-field="ml.reserved_uom_qty"/><span t-if="o.state == 'done'" t-field="ml.qty_done"/><span t-field="ml.product_uom_id" groups="uom.group_uom"/></td><td t-if="o.picking_type_id.code != 'incoming'" groups="stock.group_stock_multi_locations"><span t-esc="ml.location_id.display_name"/><t t-if="ml.package_id"><span t-field="ml.package_id"/></t></td><td t-if="o.picking_type_id.code != 'outgoing'" groups="stock.group_stock_multi_locations"><div><span t-field="ml.location_dest_id"/><t t-if="ml.result_package_id"><span t-field="ml.result_package_id"/></t></div></td><td class=" text-center h6" t-if="has_serial_number"><div t-if="has_serial_number and (ml.lot_id or ml.lot_name)" t-esc="ml.lot_id.name or ml.lot_name" t-options="{'widget': 'barcode', 'humanreadable': 1, 'width': 400, 'height': 100, 'img_style': 'width:100%;height:35px;'}"/></td><td class="text-center" t-if="has_barcode"><t t-if="product_barcode != ml.product_id.barcode"><span t-if="ml.product_id and ml.product_id.barcode"><div t-field="ml.product_id.barcode" t-options="{'widget': 'barcode', 'symbology': 'auto', 'width': 400, 'height': 100, 'quiet': 0, 'img_style': 'height:35px;'}"/></span><t t-set="product_barcode" t-value="ml.product_id.barcode"/></t></td></tr></t></tbody></table>
-->
<table class="table table-sm" t-if="o.package_level_ids and o.picking_type_entire_packs and o.state in ['assigned', 'done']">
<thead>
<tr>
<th name="th_package">Package</th>
<th name="th_pko_from" t-if="o.picking_type_id.code != 'incoming'" groups="stock.group_stock_multi_locations">From</th>
<th name="th_pki_from" t-if="o.picking_type_id.code != 'outgoing'" groups="stock.group_stock_multi_locations">To</th>
</tr>
</thead>
<tbody>
<tr t-foreach="o.package_level_ids.sorted(key=lambda p: p.package_id.name)" t-as="package">
<t t-set="package" t-value="package.with_context(picking_id=o.id)"/>
<td name="td_pk_barcode">
<div t-field="package.package_id.name" t-options="{'widget': 'barcode', 'humanreadable': 1, 'width': 600, 'height': 100, 'img_style': 'width:300px;height:50px;margin-left: -50px;'}"/>
<br/>
</td>
<td t-if="o.picking_type_id.code != 'incoming'" groups="stock.group_stock_multi_locations">
<span t-field="package.location_id"/>
</td>
<td t-if="o.picking_type_id.code != 'outgoing'" groups="stock.group_stock_multi_locations">
<span t-field="package.location_dest_id"/>
</td>
</tr>
</tbody>
</table>
<t t-set="no_reserved_product" t-value="o.move_ids.filtered(lambda x: x.product_uom_qty != x.reserved_availability and x.move_line_ids and x.state!='done')"/>
<p t-if="o.state in ['draft', 'waiting', 'confirmed'] or no_reserved_product">
<i class="fa fa-exclamation-triangle"/>
All products could not be reserved. Click on the "Check Availability" button to try to reserve products.

</p>
<p t-field="o.note"/>
</div>
</t>
</t>
</t>
</t>

Autor

Please see below for traceback:

RPC_ERROR
Odoo Server Error
Traceback (most recent call last):
File "/home/odoo/src/odoo/16.0/odoo/models.py", line 5134, in ensure_one
_id, = self._ids
ValueError: too many values to unpack (expected 1)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "<2243>", line 1301, in template_2243
File "<2243>", line 1283, in template_2243_content
File "<2243>", line 1265, in template_2243_t_call_0
File "<2243>", line 759, in template_2243_t_call_1
File "/home/odoo/src/odoo/16.0/odoo/fields.py", line 1153, in __get__
record.ensure_one()
File "/home/odoo/src/odoo/16.0/odoo/models.py", line 5137, in ensure_one
raise ValueError("Expected singleton: %s" % self)
ValueError: Expected singleton: stock.location(8, 496)

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/odoo/src/odoo/16.0/addons/web/controllers/report.py", line 113, in report_download
response = self.report_routes(reportname, docids=docids, converter=converter, context=context)
File "/home/odoo/src/odoo/16.0/odoo/http.py", line 697, in route_wrapper
result = endpoint(self, *args, **params_ok)
File "/home/odoo/src/odoo/16.0/addons/web/controllers/report.py", line 42, in report_routes
pdf = report.with_context(context)._render_qweb_pdf(reportname, docids, data=data)[0]
File "/home/odoo/src/odoo/16.0/addons/account/models/ir_actions_report.py", line 58, in _render_qweb_pdf
return super()._render_qweb_pdf(report_ref, res_ids=res_ids, data=data)
File "/home/odoo/src/odoo/16.0/odoo/addons/base/models/ir_actions_report.py", line 807, in _render_qweb_pdf
collected_streams = self._render_qweb_pdf_prepare_streams(report_ref, data, res_ids=res_ids)
File "/home/odoo/src/odoo/16.0/addons/account_edi_ubl_cii/models/ir_actions_report.py", line 58, in _render_qweb_pdf_prepare_streams
collected_streams = super()._render_qweb_pdf_prepare_streams(report_ref, data, res_ids=res_ids)
File "/home/odoo/src/odoo/16.0/addons/account_edi/models/ir_actions_report.py", line 14, in _render_qweb_pdf_prepare_streams
collected_streams = super()._render_qweb_pdf_prepare_streams(report_ref, data, res_ids=res_ids)
File "/home/odoo/src/odoo/16.0/addons/account/models/ir_actions_report.py", line 20, in _render_qweb_pdf_prepare_streams
return super()._render_qweb_pdf_prepare_streams(report_ref, data, res_ids=res_ids)
File "/home/odoo/src/odoo/16.0/odoo/addons/base/models/ir_actions_report.py", line 708, in _render_qweb_pdf_prepare_streams
html = self.with_context(**additional_context)._render_qweb_html(report_ref, res_ids_wo_stream, data=data)[0]
File "/home/odoo/src/enterprise/16.0/web_studio/models/ir_actions_report.py", line 19, in _render_qweb_html
return super(IrActionsReport, self)._render_qweb_html(report_ref, docids, data)
File "/home/odoo/src/odoo/16.0/odoo/addons/base/models/ir_actions_report.py", line 884, in _render_qweb_html
return self._render_template(report.report_name, data), 'html'
File "/home/odoo/src/odoo/16.0/odoo/addons/base/models/ir_actions_report.py", line 623, in _render_template
return view_obj._render_template(template, values).encode()
File "/home/odoo/src/odoo/16.0/addons/website/models/ir_ui_view.py", line 418, in _render_template
return super()._render_template(template, values=values)
File "/home/odoo/src/odoo/16.0/odoo/addons/base/models/ir_ui_view.py", line 2128, in _render_template
return self.env['ir.qweb']._render(template, values)
File "/home/odoo/src/odoo/16.0/odoo/tools/profiler.py", line 292, in _tracked_method_render
return method_render(self, template, values, **options)
File "/home/odoo/src/odoo/16.0/odoo/addons/base/models/ir_qweb.py", line 580, in _render
result = ''.join(rendering)
File "<2243>", line 1307, in template_2243
odoo.addons.base.models.ir_qweb.QWebException: Error while render the template
ValueError: Expected singleton: stock.location(8, 496)
Template: stock.report_picking_copy_1
Path: /t/t/t/t/div/table[1]/tbody/t/tr/td[5]/span
Node: <span t-esc="ml.move_line_ids.location_id.display_name"/>

The above server error caused the following client error:
RPC_ERROR: Odoo Server Error
at makeErrorFromResponse (https://nextarusa.odoo.com/web/assets/30713-a7e7860/web.assets_backend.min.js:992:163)
at decoder.onload (https://nextarusa.odoo.com/web/assets/30713-a7e7860/web.assets_backend.min.js:980:7)

here in this line: <span t-esc="ml.move_line_ids.location_id.display_name"/ ml.move_line_ids has multiple lines in it and thus it shows error,

either you have to iterate this over for loop or adjust like this: <span t-esc="ml.move_line_ids[0].location_id.display_name"/

Autor

Thank you so much Niyas. Your solution fixed the issue.

Autor

Hi Niyas,

Can I ask for your help once more? The previous error has been fixed, however I'm getting a new error with the following traceback:

RPC_ERROR
Odoo Server Error
Traceback (most recent call last):
File "<2243>", line 1301, in template_2243
File "<2243>", line 1283, in template_2243_content
File "<2243>", line 1265, in template_2243_t_call_0
File "<2243>", line 759, in template_2243_t_call_1
File "/home/odoo/src/odoo/16.0/odoo/models.py", line 5877, in __getitem__
return self.browse((self._ids[key],))
IndexError: tuple index out of range

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
File "/home/odoo/src/odoo/16.0/addons/web/controllers/report.py", line 113, in report_download
response = self.report_routes(reportname, docids=docids, converter=converter, context=context)
File "/home/odoo/src/odoo/16.0/odoo/http.py", line 697, in route_wrapper
result = endpoint(self, *args, **params_ok)
File "/home/odoo/src/odoo/16.0/addons/web/controllers/report.py", line 42, in report_routes
pdf = report.with_context(context)._render_qweb_pdf(reportname, docids, data=data)[0]
File "/home/odoo/src/odoo/16.0/addons/account/models/ir_actions_report.py", line 58, in _render_qweb_pdf
return super()._render_qweb_pdf(report_ref, res_ids=res_ids, data=data)
File "/home/odoo/src/odoo/16.0/odoo/addons/base/models/ir_actions_report.py", line 807, in _render_qweb_pdf
collected_streams = self._render_qweb_pdf_prepare_streams(report_ref, data, res_ids=res_ids)
File "/home/odoo/src/odoo/16.0/addons/account_edi_ubl_cii/models/ir_actions_report.py", line 58, in _render_qweb_pdf_prepare_streams
collected_streams = super()._render_qweb_pdf_prepare_streams(report_ref, data, res_ids=res_ids)
File "/home/odoo/src/odoo/16.0/addons/account_edi/models/ir_actions_report.py", line 14, in _render_qweb_pdf_prepare_streams
collected_streams = super()._render_qweb_pdf_prepare_streams(report_ref, data, res_ids=res_ids)
File "/home/odoo/src/odoo/16.0/addons/account/models/ir_actions_report.py", line 20, in _render_qweb_pdf_prepare_streams
return super()._render_qweb_pdf_prepare_streams(report_ref, data, res_ids=res_ids)
File "/home/odoo/src/odoo/16.0/odoo/addons/base/models/ir_actions_report.py", line 708, in _render_qweb_pdf_prepare_streams
html = self.with_context(**additional_context)._render_qweb_html(report_ref, res_ids_wo_stream, data=data)[0]
File "/home/odoo/src/enterprise/16.0/web_studio/models/ir_actions_report.py", line 19, in _render_qweb_html
return super(IrActionsReport, self)._render_qweb_html(report_ref, docids, data)
File "/home/odoo/src/odoo/16.0/odoo/addons/base/models/ir_actions_report.py", line 884, in _render_qweb_html
return self._render_template(report.report_name, data), 'html'
File "/home/odoo/src/odoo/16.0/odoo/addons/base/models/ir_actions_report.py", line 623, in _render_template
return view_obj._render_template(template, values).encode()
File "/home/odoo/src/odoo/16.0/addons/website/models/ir_ui_view.py", line 418, in _render_template
return super()._render_template(template, values=values)
File "/home/odoo/src/odoo/16.0/odoo/addons/base/models/ir_ui_view.py", line 2128, in _render_template
return self.env['ir.qweb']._render(template, values)
File "/home/odoo/src/odoo/16.0/odoo/tools/profiler.py", line 292, in _tracked_method_render
return method_render(self, template, values, **options)
File "/home/odoo/src/odoo/16.0/odoo/addons/base/models/ir_qweb.py", line 580, in _render
result = ''.join(rendering)
File "<2243>", line 1307, in template_2243
odoo.addons.base.models.ir_qweb.QWebException: Error while render the template
IndexError: tuple index out of range
Template: stock.report_picking_copy_1
Path: /t/t/t/t/div/table[1]/tbody/t/tr/td[5]/span
Node: <span t-esc="ml.move_line_ids[0].location_id.display_name"/>

The above server error caused the following client error:
RPC_ERROR: Odoo Server Error
at makeErrorFromResponse (https://nextarusa.odoo.com/web/assets/30970-a8f8161/web.assets_backend.min.js:992:163)
at decoder.onload (https://nextarusa.odoo.com/web/assets/30970-a8f8161/web.assets_backend.min.js:980:7)

<span t-esc="ml.move_line_ids[0].location_id.display_name"/>

--->

<t t-if="ml.move_line_ids">
<span t-esc="ml.move_line_ids[0].location_id.display_name"/>
</t>

Autor

That did it. Thank you so much!