[IMP] no need to manually set store_fname and remember name of templat eattachment

This commit is contained in:
Stepan Savelyev 2019-12-04 15:31:40 +05:00
parent da2432a477
commit a65bfffc48
6 changed files with 22 additions and 19 deletions

View File

@ -5,8 +5,5 @@
- db_name - db_name
Чтобы создать шаблон нужно: Чтобы создать шаблон нужно:
1. Создать вложение из .doc* файла и запомнить его name и store_fname 1. Зайти в Wizard генерации документа и создать из него Шаблон, в котором привязать вложение к нему
2. Зайти в Wizard генерации документа и создать из него Шаблон, в котором указать: 2. Сгенерировать шаблон
- name
- store_fname
3. Сгенерировать шаблон

View File

@ -10,7 +10,7 @@ class ResPartnerContractBinary(http.Controller):
@http.route('/web/binary/get_compiled_contract') @http.route('/web/binary/get_compiled_contract')
def download_compiled_contract(self, doc_id, doc_name): def download_compiled_contract(self, doc_id, doc_name):
contract_wizard = http.request.env['res.partner.contract.wizard'].sudo().browse(int(doc_id)) contract_wizard = http.request.env['res.partner.contract.wizard'].sudo().browse(int(doc_id))
file_content = contract_wizard.get_docx_contract_1() file_content = contract_wizard.get_docx_contract_1().read()
headers = datastructures.Headers() headers = datastructures.Headers()
headers.add('Content-Disposition', 'attachment', filename=doc_name) headers.add('Content-Disposition', 'attachment', filename=doc_name)
return http.request.make_response(file_content, headers) return http.request.make_response(file_content, headers)

View File

@ -16,11 +16,11 @@ class ContractWizard(models.TransientModel):
# TODO: Move _get_default_+ method down # TODO: Move _get_default_+ method down
def _get_default_template(self): def _get_default_template(self):
_template = self.env['res.partner.contract.template'].search( _template = self.env['res.partner.contract.template'].search([
[('is_contract_template', '=', True)]) ('is_default', '=', True)
])
if _template: if _template:
return _template[0].id return _template[0].id
else:
return False return False
def _get_default_partner(self): def _get_default_partner(self):
@ -508,7 +508,7 @@ class ContractWizard(models.TransientModel):
def get_docx_contract_1(self): def get_docx_contract_1(self):
odoo_data_dir = config.get("data_dir") odoo_data_dir = config.get("data_dir")
odoo_bd = config.get("db_name") odoo_bd = config.get("db_name")
filename = self.template.store_fname filename = self.template.attachment_id.store_fname
full_path = '{}/filestore/{}/{}'.format( full_path = '{}/filestore/{}/{}'.format(
odoo_data_dir, odoo_bd, filename) odoo_data_dir, odoo_bd, filename)
context = self._generate_context() context = self._generate_context()

View File

@ -77,9 +77,13 @@ class AnnexType(models.Model):
class ContractTemplate(models.Model): class ContractTemplate(models.Model):
_name = 'res.partner.contract.template' _name = 'res.partner.contract.template'
_inherit = 'ir.attachment'
is_contract_template = fields.Boolean( attachment_id = fields.Many2one(
srting='Is this document contract template?', 'ir.attachment',
default=True string="Template Attachment",
) # TODO: srting -> string required=True,
)
is_default = fields.Boolean(
string='Default Template',
default=False,
)

View File

@ -42,7 +42,9 @@
<form> <form>
<group> <group>
<group name="template" string="Templates"> <group name="template" string="Templates">
<field name="template" string="Templates"/> <field name="template" string="Templates">
<field name="attachment_id"/>
</field>
</group> </group>
<group name="partner" string="Partner parameters"> <group name="partner" string="Partner parameters">
<field name="partner_id"/> <field name="partner_id"/>

View File

@ -134,8 +134,8 @@
<field name="view_mode">tree,form,graph</field> <field name="view_mode">tree,form,graph</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Template"> <tree string="Template">
<field name="name"/> <field name="attachment_id"/>
<field name="is_contract_template"/> <field name="is_default"/>
</tree> </tree>
</field> </field>
</record> </record>