Public release from ruodoo-project: 19.0 - 2026-05-31 21:19:12 UTC
This commit is contained in:
1
custom_report_field/wizard/__init__.py
Normal file
1
custom_report_field/wizard/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
from . import custom_report_field_values_wizard
|
||||
@ -0,0 +1,95 @@
|
||||
from odoo import api, fields, models
|
||||
from odoo.addons.web.controllers.utils import clean_action
|
||||
from odoo.exceptions import ValidationError
|
||||
|
||||
|
||||
class CustomReportFieldValuesWizard(models.TransientModel):
|
||||
_name = "custom.report.field.values.wizard"
|
||||
_description = "Custom report values field verify wizard"
|
||||
|
||||
ir_actions_report_id = fields.Many2one(
|
||||
"ir.actions.report",
|
||||
string="Report",
|
||||
)
|
||||
field_values_ids = fields.One2many(
|
||||
comodel_name="custom.report.field.values.wizard.line",
|
||||
inverse_name="wizard_id",
|
||||
string="Custom report field values",
|
||||
)
|
||||
|
||||
def _check_records_amount(self):
|
||||
"""
|
||||
Checks source records for report generation. If more than one - raise error.
|
||||
"""
|
||||
active_model = self._context.get("active_model")
|
||||
if active_model:
|
||||
record_id = self.env[active_model].browse(self._context.get("active_id"))
|
||||
record_ids = self.env[active_model].browse(self._context.get("active_ids"))
|
||||
records_for_report = record_id | record_ids
|
||||
if len(records_for_report) > 1:
|
||||
raise ValidationError(
|
||||
"Reports with custom fields do not supports bunch report generation.\nPrint them one at a time."
|
||||
)
|
||||
|
||||
@api.onchange("ir_actions_report_id")
|
||||
def _onchange_ir_actions_report_id(self):
|
||||
self._check_records_amount()
|
||||
custom_values_for_report = self.env["custom.report.field"].search(
|
||||
[
|
||||
("ir_actions_report_id", "=", self.ir_actions_report_id.id),
|
||||
("visible", "=", True),
|
||||
]
|
||||
)
|
||||
self.field_values_ids = [
|
||||
(
|
||||
6,
|
||||
False,
|
||||
self.env["custom.report.field.values.wizard.line"]
|
||||
.create(
|
||||
[
|
||||
{
|
||||
"name": field_rec.name,
|
||||
"value": field_rec.compute_value(self.ir_actions_report_id),
|
||||
"technical_name": field_rec.technical_name,
|
||||
"description": field_rec.description,
|
||||
}
|
||||
for field_rec in custom_values_for_report
|
||||
]
|
||||
)
|
||||
.ids,
|
||||
)
|
||||
]
|
||||
|
||||
def get_report(self):
|
||||
self.ensure_one()
|
||||
cleaned_report = False
|
||||
action_id = self.ir_actions_report_id.id
|
||||
ctx = dict(self._context)
|
||||
ctx.update({"report_values_validated": True})
|
||||
report = self.env["ir.actions.report"].sudo().browse([action_id]).read()
|
||||
if report:
|
||||
cleaned_report = clean_action(report[0], env=self.env)
|
||||
cleaned_report["context"] = ctx
|
||||
return cleaned_report
|
||||
|
||||
|
||||
class CustomReportFieldValuesWizardLine(models.TransientModel):
|
||||
_name = "custom.report.field.values.wizard.line"
|
||||
_description = "Custom report values field verify wizard"
|
||||
|
||||
wizard_id = fields.Many2one(
|
||||
"custom.report.field.values.wizard",
|
||||
)
|
||||
|
||||
name = fields.Char(
|
||||
string="Name",
|
||||
)
|
||||
value = fields.Char(
|
||||
string="Value",
|
||||
)
|
||||
technical_name = fields.Char(
|
||||
string="Technical Name",
|
||||
)
|
||||
description = fields.Char(
|
||||
string="Description",
|
||||
)
|
||||
@ -0,0 +1,27 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="custom_report_values_wizard_view_form" model="ir.ui.view">
|
||||
<field name="name">Verify report values</field>
|
||||
<field name="model">custom.report.field.values.wizard</field>
|
||||
<field name="arch" type="xml">
|
||||
<form create="0" delete="0">
|
||||
<group string="Report values">
|
||||
<field name="ir_actions_report_id" invisible="1"/>
|
||||
<field name="field_values_ids" nolabel="1" colspan="4" readonly="1" view_mode="list">
|
||||
<list>
|
||||
<field name="name"/>
|
||||
<field name="value"/>
|
||||
<field name="description"/>
|
||||
<field name="technical_name" invisible="1"/>
|
||||
</list>
|
||||
</field>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="get_report" type="object" string="Get report"/>
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
||||
Reference in New Issue
Block a user