aso
(asoo)
April 29, 2021, 11:43am
1
I want to print the columns of table One2many
in my report :
This is the code :
<table:table table:name="Table3" table:style-name="Table3">
<table:table-column table:style-name="Table3.A" table:number-columns-repeated="3"/>
<table:table-header-rows>
<table:table-row>
<table:table-cell table:style-name="Table3.A1" office:value-type="string">
<text:p text:style-name="P13">Description</text:p>
</table:table-cell>
<table:table-cell table:style-name="Table3.A1" office:value-type="string">
<text:p text:style-name="P13">Quantity</text:p>
</table:table-cell>
<table:table-cell table:style-name="Table3.A1" office:value-type="string">
<text:p text:style-name="P13">Bright</text:p>
</table:table-cell>
</table:table-row>
</table:table-header-rows>
<table:table-row>
<table:table-cell table:style-name="Table3.A2" table:number-columns-spanned="3" office:value-type="string">
<text:p text:style-name="Table_20_Contents"><text:placeholder text:placeholder-type="text"><for each=" Class_Bought in records"></text:placeholder></text:p>
</table:table-cell>
<table:covered-table-cell/>
<table:covered-table-cell/>
</table:table-row>
<table:table-row>
<table:table-cell table:style-name="Table3.B3" office:value-type="string">
<text:p text:style-name="P10"><text:placeholder text:placeholder-type="text"><Class_Bought.description></text:placeholder></text:p>
</table:table-cell>
<table:table-cell table:style-name="Table3.C3" office:value-type="string">
<text:p text:style-name="P10"><text:placeholder text:placeholder-type="text"><Class_Bought.quantity></text:placeholder></text:p>
</table:table-cell>
<table:table-cell table:style-name="Table3.C3" office:value-type="string">
<text:p text:style-name="P10"><text:placeholder text:placeholder-type="text"><Class_Bought.bright></text:placeholder></text:p>
</table:table-cell>
</table:table-row>
</table:table>
`<text:p text:style-name="Text_20_body"><text:placeholder text:placeholder-type="text"></for></text:placeholder></text:p>`
But when i want to download it , there is no error but when i was saw the report.fodt, i didn’t find the tables that i already filled it out on the interface tryton
can anyone help me to know what’s wrong the code or link to me the correct steps to print the columns of table One2many
on the report.
edbo
April 29, 2021, 11:53am
2
If this is what you have created, you clearly messed up things. Your /for
is complete outside the table tag. This should be in the table as a separate row like the start of the for
loop.
Check also the variable Class_Bought
. No idea if it makes any difference when you lowercase it into something like classbought
.
aso
(asoo)
April 29, 2021, 5:13pm
3
it’s the same i put /for
after </table:table-cell>
but nothing change , Have you please a simple example or can u link to me if there is a documentation about how to do that .
I have define the class " class_bought
" like that
class ClassBought(DeactivableMixin, sequence_ordered(),ModelSQL, ModelView):
__name__ = 'prod. class_bought'
description = fields.Char('Description', translate=True,required=True,
)
quantity = fields.Char('Quantity', translate=True
)
bright = fields.Char('Bright', translate=True
)
also
class ClassBoughtReport(Report):
__name__ = 'prod. class_bought'
@classmethod
def get_context(cls, records, header):
pool = Pool()
ClassBought = pool.get('prod. class_bought')
context = super().get_context(records, header)
bought_id = Transaction().context.get('class_bought')
class_bought = ClassBought(bought_id) if bought_id else None
context['bought_id'] = class_bought
return context
am hesitate about the syntax ```
for each=" Class_Bought in records is it correct to print the table of “one2many”
PS ;Please if you have a simple example can you give it to me or link to me a documentation talking aboput how to print the one2many in reports
edbo
April 29, 2021, 5:54pm
4
I don’t understand your comments about a One2Many
field. I don’t see any.
You cannot have prod.class_bought
twice. You don’t even have to have the second one to define your report. See the documentation about Models and Define reports in XML
So in your case the Python code:
class ClassBought(DeactivableMixin, sequence_ordered(),ModelSQL, ModelView):
__name__ = 'prod.class_bought'
description = fields.Char('Description', translate=True,required=True)
quantity = fields.Char('Quantity', translate=True)
bright = fields.Char('Bright', translate=True)
The XML code to define your report:
<record model="ir.action.report" id="report_bought">
<field name="name">Bought Class</field>
<field name="report_name">prod.class_bought.report</field>
<field name="model">prod.class_bought</field>
<field name="report">my_module/my_reportname.fodt</field>
</record>
<record model="ir.action.keyword" id="report_bought_keyword">
<field name="keyword">form_print</field>
<field name="model">prod.class_bought,-1</field>
<field name="action" ref="report_bought"/>
</record>
You should now be able to see your report available on the ClassBought
view.
Your report my_module/my_reportname.fodt
have something like:
<table:table table:name="Table2" table:style-name="Table2">
<table:table-column table:style-name="Table2.A"/>
<table:table-column table:style-name="Table2.B"/>
<table:table-column table:style-name="Table2.C"/>
<table:table-column table:style-name="Table2.D"/>
<table:table-row table:style-name="Table2.1">
<table:table-cell table:style-name="Table2.A1" table:number-columns-spanned="4" office:value-type="string">
<text:p text:style-name="P6"><text:placeholder text:placeholder-type="text"><for each="cb in records"></text:placeholder><text:span text:style-name="T7"><text:placeholder text:placeholder-type="text"><set_lang(lang and lang.code or 'en')></text:placeholder></text:span><text:span text:style-name="T7"><text:placeholder text:placeholder-type="text"><move.set_lang(lang and lang.code or 'en')></text:placeholder></text:span></text:p>
</table:table-cell>
<table:covered-table-cell/>
<table:covered-table-cell/>
<table:covered-table-cell/>
</table:table-row>
<table:table-row table:style-name="Table2.2">
<table:table-cell table:style-name="Table2.A2" table:number-columns-spanned="3" office:value-type="string">
<text:p text:style-name="P40"><text:placeholder text:placeholder-type="text"><cb.description></text:placeholder></text:span></text:p>
</table:table-cell>
<table:covered-table-cell/>
<table:covered-table-cell/>
<table:table-cell table:style-name="Table2.D2" office:value-type="string">
<text:p text:style-name="P40"><text:placeholder text:placeholder-type="text"><cb.quantity></text:placeholder></text:span></text:p>
</table:table-cell>
</table:table-row>
<table:table-row>
<table:table-cell table:style-name="Table2.A17" table:number-columns-spanned="4" office:value-type="string">
<text:p text:style-name="P5"><text:placeholder text:placeholder-type="text"></for></text:placeholder></text:p>
</table:table-cell>
<table:covered-table-cell/>
<table:covered-table-cell/>
<table:covered-table-cell/>
</table:table-row>
</table:table>
I haven’t tested it myself, but hopefully it will get you starting.
aso
(asoo)
April 29, 2021, 7:01pm
5
yes i already did that , thank you edbo
am stuck on how i should print the columns of “One2Many” (because the columns should be unlimited)
see the photo may be you can understand me
edbo
April 29, 2021, 8:07pm
7
You just have to put another for
loop into your report. You can take a look at the sale
module how the sale.line
model is related to the sale.sale
model. When you look at the sale order report, you have a second nested for-loop which will walk through all the lines related to that sale.
1 Like