diff --git a/README.md b/README.md index 5b644b3..77ea50a 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,5 @@ - db_name Чтобы создать шаблон нужно: -1. Создать вложение из .doc* файла и запомнить его name и store_fname -2. Зайти в Wizard генерации документа и создать из него Шаблон, в котором указать: - - name - - store_fname -3. Сгенерировать шаблон \ No newline at end of file +1. Зайти в Wizard генерации документа и создать из него Шаблон, в котором привязать вложение к нему +2. Сгенерировать шаблон \ No newline at end of file diff --git a/controllers/controllers.py b/controllers/controllers.py index eb3ea3a..5f89162 100644 --- a/controllers/controllers.py +++ b/controllers/controllers.py @@ -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) diff --git a/models/contract_wizard.py b/models/contract_wizard.py index 58f1846..8447643 100644 --- a/models/contract_wizard.py +++ b/models/contract_wizard.py @@ -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() diff --git a/models/res_partner_contract.py b/models/res_partner_contract.py index 896aac0..6156423 100644 --- a/models/res_partner_contract.py +++ b/models/res_partner_contract.py @@ -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, + ) diff --git a/views/contract_wizard.xml b/views/contract_wizard.xml index 9e6105f..9426f13 100644 --- a/views/contract_wizard.xml +++ b/views/contract_wizard.xml @@ -42,7 +42,9 @@
- + + + diff --git a/views/res_partner.xml b/views/res_partner.xml index 3ca8442..f72d329 100644 --- a/views/res_partner.xml +++ b/views/res_partner.xml @@ -134,8 +134,8 @@ tree,form,graph - - + +