From da4f2b89662468694a95ded60a29378f1acbec32 Mon Sep 17 00:00:00 2001 From: wan Date: Fri, 13 Nov 2020 13:22:38 +0000 Subject: [PATCH] [FIX] l10n_cl: manage document type for generic demo data Part of task 2124952 Amend the demo data to populate required fields added in dependencies of l10n_cl. The field l10n_latam_document_number is not required if the journal is not using Latam invoice documents. --- addons/l10n_cl/__init__.py | 1 + addons/l10n_cl/demo/__init__.py | 3 ++ addons/l10n_cl/demo/account_demo.py | 42 +++++++++++++++++++ .../views/account_move_view.xml | 4 +- 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 addons/l10n_cl/demo/__init__.py create mode 100644 addons/l10n_cl/demo/account_demo.py diff --git a/addons/l10n_cl/__init__.py b/addons/l10n_cl/__init__.py index be9f4fab00a..0573c49be44 100644 --- a/addons/l10n_cl/__init__.py +++ b/addons/l10n_cl/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. from . import models +from . import demo diff --git a/addons/l10n_cl/demo/__init__.py b/addons/l10n_cl/demo/__init__.py new file mode 100644 index 00000000000..34471da8b67 --- /dev/null +++ b/addons/l10n_cl/demo/__init__.py @@ -0,0 +1,3 @@ +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import account_demo diff --git a/addons/l10n_cl/demo/account_demo.py b/addons/l10n_cl/demo/account_demo.py new file mode 100644 index 00000000000..ba0ff092b28 --- /dev/null +++ b/addons/l10n_cl/demo/account_demo.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +import logging + +from odoo import api, models + +_logger = logging.getLogger(__name__) + + +class AccountChartTemplate(models.Model): + _inherit = "account.chart.template" + + @api.model + def _get_demo_data(self): + yield ('res.partner', { + 'base.res_partner_12': { + 'l10n_cl_sii_taxpayer_type': '4', + }, + 'base.res_partner_2': { + 'l10n_cl_sii_taxpayer_type': '4', + }, + }) + yield ('l10n_latam.document.type', { + 'l10n_cl.dc_fe_dte': {'active': True}, + }) + for model, data in super()._get_demo_data(): + yield model, data + + @api.model + def _get_demo_data_move(self): + ref = self.env.ref + cid = self.env.company.id + foreign = ref('l10n_cl.dc_fe_dte').id + model, data = super()._get_demo_data_move() + self.env['account.journal'].search([ + ('type', '=', 'purchase'), + ('company_id', '=', self.env.company.id), + ]).l10n_latam_use_documents = False + data[f'{cid}_demo_invoice_1']['l10n_latam_document_type_id'] = foreign + data[f'{cid}_demo_invoice_2']['l10n_latam_document_type_id'] = foreign + data[f'{cid}_demo_invoice_3']['l10n_latam_document_type_id'] = foreign + data[f'{cid}_demo_invoice_followup']['l10n_latam_document_type_id'] = foreign + return model, data diff --git a/addons/l10n_latam_invoice_document/views/account_move_view.xml b/addons/l10n_latam_invoice_document/views/account_move_view.xml index 28d19bccc4a..751abf90a08 100644 --- a/addons/l10n_latam_invoice_document/views/account_move_view.xml +++ b/addons/l10n_latam_invoice_document/views/account_move_view.xml @@ -45,7 +45,9 @@ attrs="{'invisible': [('l10n_latam_use_documents', '=', False)], 'required': [('l10n_latam_use_documents', '=', True)], 'readonly': [('posted_before', '=', True)]}" domain="[('id', 'in', l10n_latam_available_document_type_ids)]" options="{'no_open': True, 'no_create': True}"/> + attrs="{'invisible': ['|', ('l10n_latam_use_documents', '=', False), ('l10n_latam_manual_document_number', '=', False), '|', '|', ('l10n_latam_use_documents', '=', False), ('highest_name', '!=', False), ('state', '!=', 'draft')], + 'required': [('l10n_latam_use_documents', '=', True), '|', ('l10n_latam_manual_document_number', '=', True), ('highest_name', '=', False)], + 'readonly': [('posted_before', '=', True), ('state', '!=', 'draft')]}"/>