Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
2 Besvarelser
226 Visninger

Hello there,


I have added a custom field named "Reference lot/serial" in MO


that field needs to be added to the traceability report,



Add that custom field as a separate column in this report.

How can I add this? Is there any separate model for this?

If there is any idea, kindly let me know. 

Note: Odoo16 e+


Thank you!

Avatar
Kassér
Forfatter Bedste svar

 NOTE: The "ref_lot_serial_number" field is added in stock_move

models/traceability_report.py

from odoo import models, api

class MrpStockReport(models.TransientModel):
_inherit = 'stock.traceability.report'

def _make_dict_move(self, level, parent_id, move_line, unfoldable=False):

result = super()._make_dict_move(level, parent_id, move_line, unfoldable)

ref_lot_serial = move_line.move_id.ref_lot_serial_number if move_line.move_id.ref_lot_serial_number else ''

print(f"level {level} parent_id {parent_id} move_line {move_line} ref_lot_serial {ref_lot_serial}")

for rec in result:
rec['ref_lot_serial_number'] = ref_lot_serial

print(f"result {result}")
return result

@api.model
def _final_vals_to_lines(self, final_vals, level):

lines = super()._final_vals_to_lines(final_vals, level)

for line in lines:
line['ref_lot_serial_number'] = ''

matching = next((f for f in final_vals if f['model_id'] == line['model_id']), None)
if matching and 'ref_lot_serial_number' in matching:
line['ref_lot_serial_number'] = matching['ref_lot_serial_number']

line['columns'].insert(4,line['ref_lot_serial_number'])

return lines

views/traceability_report.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<template id="inherit_report_stock_inventory" inherit_id="stock.report_stock_inventory">
<xpath expr="//thead/tr[@class='o_report_header']/th[contains(., 'Lot/Serial #')]" position="after">
<th class="o_report_line_header">Ref Lot/Serial</th>
</xpath>
</template>

<template id="inherit_report_stock_body_print" inherit_id="stock.report_stock_body_print">
<xpath expr="//thead/tr[@class='o_report_header']/th[contains(., 'Lot/Serial #')]" position="after">
<th class="o_report_line_header">Ref Lot/Serial</th>
</xpath>
</template>
</odoo>


the result:


Avatar
Kassér
Bedste svar

Hii,

Here is custom model please try this

Python: Add Custom Field
you will already add

XML: Extend Traceability Report Template

In your custom module (views/report_traceability_line_inherit.xml), use the following code:

<odoo> <!-- Inherit the QWeb template used for the traceability report --> <template id="report_traceability_line_inherit_ref_lot" inherit_id="stock.report_traceability_line"> <!-- Add new column header --> <xpath expr="//thead/tr" position="inside"> <th>Reference Lot/Serial</th> </xpath> <!-- Add new column data --> <xpath expr="//tbody/tr" position="inside"> <td> <t t-esc="line.reference_lot_serial or ''"/> </td> </xpath> </template> </odoo>

__manifest__.py

Ensure the view is loaded in your manifest:


'data': [ 'views/report_traceability_line_inherit.xml', ],

i hope it is usefull

Avatar
Kassér
Forfatter

Hello there,
Thanks for you reply, I customized it yesterday

Related Posts Besvarelser Visninger Aktivitet
0
nov. 17
3408
0
dec. 17
4998
0
okt. 24
836
0
jun. 17
7914
0
jul. 25
354