diff --git a/__manifest__.py b/__manifest__.py index 95d8003..accd7ce 100644 --- a/__manifest__.py +++ b/__manifest__.py @@ -17,7 +17,6 @@ "security/ir.model.access.csv", "views/res_partner_contract.xml", "views/res_partner_contract_annex.xml", - "views/res_partner_template_print.xml", "views/res_partner.xml", "views/sale_order.xml", "wizard/res_partner_contract_wizard.xml", diff --git a/models/res_partner_contract.py b/models/res_partner_contract.py index 841cc23..10c61b4 100644 --- a/models/res_partner_contract.py +++ b/models/res_partner_contract.py @@ -127,9 +127,9 @@ class PartnerContract(models.Model): return _(arg) -class PrintTemplate(models.Model): - _name = "res.partner.template.print" - _description = "Print Template" +class DocumentTemplate(models.Model): + _name = "res.partner.document.template" + _description = "Document Template" _order = "sequence" name = fields.Char() @@ -143,16 +143,7 @@ class PrintTemplate(models.Model): ("plc", "Private Limited Company"), ] ) + template_type = fields.Selection( + selection=[("contract", "Contract"), ("annex", "Annex"),] + ) sequence = fields.Integer() - - -class PrintTemplateContract(models.Model): - _name = "res.partner.template.print.contract" - _inherit = "res.partner.template.print" - _description = "Print Template Contract" - - -class PrintTemplateAnnex(models.Model): - _name = "res.partner.template.print.annex" - _inherit = "res.partner.template.print" - _description = "Print Template Contract Annex" diff --git a/views/res_partner.xml b/views/res_partner.xml index 14d2e48..2c09272 100644 --- a/views/res_partner.xml +++ b/views/res_partner.xml @@ -10,20 +10,11 @@ form - - - res.partner.template.print.contract.action + + + res.partner.document.template.action ir.actions.act_window - res.partner.template.print.contract - tree,form - form - - - - - res.partner.template.print.annex.action - ir.actions.act_window - res.partner.template.print.annex + res.partner.document.template tree,form form @@ -92,21 +83,10 @@ parent="res_partner_menu_contracts" sequence="1"/> - - - - - diff --git a/views/res_partner_template_print.xml b/views/res_partner_template_print.xml deleted file mode 100644 index 1a48ce6..0000000 --- a/views/res_partner_template_print.xml +++ /dev/null @@ -1,66 +0,0 @@ - - - - - - - res.partner.template.print.contract.view.tree - res.partner.template.print.contract - - - - - - - - - - - res.partner.template.print.contract.view.form - res.partner.template.print.contract - -
- - - - - - - - -
-
-
- - - - res.partner.template.print.annex.view.tree - res.partner.template.print.annex - - - - - - - - - - - res.partner.template.print.annex.view.form - res.partner.template.print.annex - -
- - - - - - - - -
-
-
- -
-
diff --git a/wizard/res_partner_contract_wizard.py b/wizard/res_partner_contract_wizard.py index 7815afb..84075aa 100644 --- a/wizard/res_partner_contract_wizard.py +++ b/wizard/res_partner_contract_wizard.py @@ -27,20 +27,16 @@ class ContractWizard(models.TransientModel): ) company_id = fields.Many2one("res.partner", string="Company") partner_id = fields.Many2one("res.partner", string="Partner") - print_template_contract = fields.Many2one( - "res.partner.template.print.contract", string="Print Template of Contract", + document_template = fields.Many2one( + "res.partner.document.template", string="Document Template", required=True, ) - print_template_annex = fields.Many2one( - "res.partner.template.print.annex", string="Print Template of Contract Annex", - ) - transient_field_ids = fields.One2many( "res.partner.contract.field.transient", "_contract_wizard_id", string="Contract Fields", ) - @api.onchange("target") + @api.onchange("document_template") def _onchange_target(self): """Creates transient fields for generate contract template Looks as a tree view of *_contract_field_transient model in xml @@ -111,21 +107,26 @@ class ContractWizard(models.TransientModel): ] # Set up template domain + template_type = { + "res.partner.contract": "contract", + "res.partner.contract.annex": "annex", + }.get(active_model, False) company_type = ( self.partner_id.company_form if self.partner_id.is_company else "person" ) + return { "domain": { - "print_template_contract": [("company_type", "=", company_type)], - "print_template_annex": [("company_type", "=", company_type)], + "document_template": [ + ("template_type", "=", template_type), + ("company_type", "=", company_type), + ], } } @api.multi def get_docx_contract(self): - template = self._get_template() - if not template: - raise UserError("Template must be set up") + template = self.document_template path_to_template = template._full_path(template.store_fname) @@ -176,11 +177,3 @@ class ContractWizard(models.TransientModel): ) return document_as_attachment - - @api.multi - def _get_template(self): - model_to_template = { - "res.partner.contract": self.print_template_contract.attachment_id, - "res.partner.contract.annex": self.print_template_annex.attachment_id, - } - return model_to_template.get(self.env.context.get("active_model"), False) diff --git a/wizard/res_partner_contract_wizard.xml b/wizard/res_partner_contract_wizard.xml index c6db322..4080854 100644 --- a/wizard/res_partner_contract_wizard.xml +++ b/wizard/res_partner_contract_wizard.xml @@ -9,7 +9,7 @@
- + @@ -43,7 +43,7 @@ - +