Public release from ruodoo-project: 19.0 - 2026-05-10 21:19:01 UTC

This commit is contained in:
CI Publish Bot
2026-05-10 21:19:11 +00:00
commit cbf9e6e6d6
1213 changed files with 183945 additions and 0 deletions

View File

@ -0,0 +1,3 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import report_template_wizard

View File

@ -0,0 +1,63 @@
import base64
from odoo import models, fields, api
from io import BytesIO
try:
from docxtpl import DocxTemplate
except ImportError:
DocxTemplate = None
class ReportTemplateWizard(models.TransientModel):
_name = 'report.template.wizard'
_description = 'Визард выбора шаблона для печати договора'
contract_id = fields.Many2one('model.contract', string='Договор', required=True)
typeformat = fields.Selection([('docx','DOCX'),
('md','MD')
], string='Формат', required=True)
template_id = fields.Many2one('contract.report.template', string='Шаблон отчета', required=True)
generated_report = fields.Binary(string='Сформированный отчет')
def print_report(self):
self.ensure_one()
template = self.template_id
contract = self.contract_id
if template.format == 'docx':
template_data = base64.b64decode(template.attachment)
docx_io = BytesIO(template_data)
doc = DocxTemplate(docx_io)
context = {
'o': contract,
'user': self.env.user,
'name': contract.name or '',
}
doc.render(context)
output_io = BytesIO()
doc.save(output_io)
output_io.seek(0)
self.generated_report = base64.b64encode(output_io.read())
self.report_filename = f'{contract.name or "report"}.docx'
return {
'type': 'ir.actions.act_url',
'url': f'/web/content/?model={self._name}&id={self.id}&field=generated_report&filename={self.report_filename}&download=true',
'target': 'self',
}
elif template.format == 'md':
md_content = f"# Отчет по договору\n\nНазвание договора: {contract.name or ''}\n"
self.generated_report = base64.b64encode(md_content.encode('utf-8'))
self.report_filename = f'{contract.name or "report"}.md'
return {
'type': 'ir.actions.act_url',
'url': f'/web/content/?model={self._name}&id={self.id}&field=generated_report&filename={self.report_filename}&download=true',
'target': 'self',
}
else:
raise UserError('Неподдерживаемый формат шаблона')

View File

@ -0,0 +1,19 @@
<odoo>
<record id="view_print_report_wizard_form" model="ir.ui.view">
<field name="name">report.template.wizard.form</field>
<field name="model">report.template.wizard</field>
<field name="arch" type="xml">
<form string="Печать по шаблону">
<group>
<field name="contract_id" invisible="1"/>
<field name="typeformat"/>
<field name="template_id" required="1" options="{'no_create': True}" domain="[('typeformat','=',typeformat)]"/>
</group>
<footer>
<button string="Печать" type="object" name="print_report" class="btn-primary"/>
<button string="Отмена" class="btn-secondary" special="cancel"/>
</footer>
</form>
</field>
</record>
</odoo>