[IMP] no need to manually set store_fname and remember name of templat eattachment
This commit is contained in:
parent
da2432a477
commit
a65bfffc48
@ -5,8 +5,5 @@
|
||||
- db_name
|
||||
|
||||
Чтобы создать шаблон нужно:
|
||||
1. Создать вложение из .doc* файла и запомнить его name и store_fname
|
||||
2. Зайти в Wizard генерации документа и создать из него Шаблон, в котором указать:
|
||||
- name
|
||||
- store_fname
|
||||
3. Сгенерировать шаблон
|
||||
1. Зайти в Wizard генерации документа и создать из него Шаблон, в котором привязать вложение к нему
|
||||
2. Сгенерировать шаблон
|
@ -10,7 +10,7 @@ class ResPartnerContractBinary(http.Controller):
|
||||
@http.route('/web/binary/get_compiled_contract')
|
||||
def download_compiled_contract(self, doc_id, doc_name):
|
||||
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.add('Content-Disposition', 'attachment', filename=doc_name)
|
||||
return http.request.make_response(file_content, headers)
|
||||
|
@ -16,12 +16,12 @@ class ContractWizard(models.TransientModel):
|
||||
|
||||
# TODO: Move _get_default_+ method down
|
||||
def _get_default_template(self):
|
||||
_template = self.env['res.partner.contract.template'].search(
|
||||
[('is_contract_template', '=', True)])
|
||||
_template = self.env['res.partner.contract.template'].search([
|
||||
('is_default', '=', True)
|
||||
])
|
||||
if _template:
|
||||
return _template[0].id
|
||||
else:
|
||||
return False
|
||||
return False
|
||||
|
||||
def _get_default_partner(self):
|
||||
current_id = self.env.context.get('active_ids')
|
||||
@ -508,7 +508,7 @@ class ContractWizard(models.TransientModel):
|
||||
def get_docx_contract_1(self):
|
||||
odoo_data_dir = config.get("data_dir")
|
||||
odoo_bd = config.get("db_name")
|
||||
filename = self.template.store_fname
|
||||
filename = self.template.attachment_id.store_fname
|
||||
full_path = '{}/filestore/{}/{}'.format(
|
||||
odoo_data_dir, odoo_bd, filename)
|
||||
context = self._generate_context()
|
||||
|
@ -77,9 +77,13 @@ class AnnexType(models.Model):
|
||||
|
||||
class ContractTemplate(models.Model):
|
||||
_name = 'res.partner.contract.template'
|
||||
_inherit = 'ir.attachment'
|
||||
|
||||
is_contract_template = fields.Boolean(
|
||||
srting='Is this document contract template?',
|
||||
default=True
|
||||
) # TODO: srting -> string
|
||||
attachment_id = fields.Many2one(
|
||||
'ir.attachment',
|
||||
string="Template Attachment",
|
||||
required=True,
|
||||
)
|
||||
is_default = fields.Boolean(
|
||||
string='Default Template',
|
||||
default=False,
|
||||
)
|
||||
|
@ -42,7 +42,9 @@
|
||||
<form>
|
||||
<group>
|
||||
<group name="template" string="Templates">
|
||||
<field name="template" string="Templates"/>
|
||||
<field name="template" string="Templates">
|
||||
<field name="attachment_id"/>
|
||||
</field>
|
||||
</group>
|
||||
<group name="partner" string="Partner parameters">
|
||||
<field name="partner_id"/>
|
||||
|
@ -134,8 +134,8 @@
|
||||
<field name="view_mode">tree,form,graph</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Template">
|
||||
<field name="name"/>
|
||||
<field name="is_contract_template"/>
|
||||
<field name="attachment_id"/>
|
||||
<field name="is_default"/>
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
Loading…
x
Reference in New Issue
Block a user