I want the report only appear if the state is only in 'transfer' and make it invisible in all state except 'transfer' state. I try the attributes menu and set it to false like menu = "False" but it doesn't appear also in 'transfer' state. Is any attributes that make the report hide depends on its state? the attrs doesn't work. Is any?
Here is my code.
<report
id="handover_info_rep"
header="False"
menu="False"
model="asset.management.handover"
string="Handover issuance receipt"
name="etsi_asset.handover_info_temp"
file="etsi_asset.handover_info_temp"
report_type="qweb-pdf"
paperformat="paperformat_handover"
/>
Many thanks.
You cannot do that in a simple way. You can use menu="False"
or menu="True"
whether if you want to show the item or not in the print menu, without condition.
You can add some condition in the render_html
method, in order to validate if the selected records are in the right state:
@api.multi
def render_html(self, data=None):
report_obj = self.env['report']
report = report_obj._get_report_from_name('etsi_asset.handover_info_temp')
model_obj = self.env[self.env.context["active_model"]].browse(self.env.context["active_ids"]
# or >> model_obj = self.env['model.name'].browse(self._ids)
for record in model_obj:
if record.state == 'some_state':
raise ValidationError(
_('This record cannot be printed in that state.')
)
docargs = {
'doc_ids': self._ids,
'doc_model': report.model,
'docs': self,
}
return report_obj.render('etsi_asset.handover_info_temp', docargs)
You can create a button with the attrs
attribute. You can add this button on the tree view or on the form view:
<button name="%(your_module.handover_info_rep)d"
string="Report name"
type="action"
attrs="{'invisible':[('state', '=', 'some_state')]}"/>