From b2a14dda03ddfb13e4ed34a22634b6b1aa3b9dcf Mon Sep 17 00:00:00 2001 From: eco-odoo Date: Wed, 17 Oct 2018 09:51:21 +0000 Subject: [PATCH] [FIX] account: onboarding fiscal year step various issues Design: remove empty space in the dialog form. Opening date: -fix move line not created introduced by c4b9c51abf5c7ac47d9ead6703a9a8dd0bc59f52. This prevented saving the opening date; -set default date to start of current year. Add a validation on fiscal year last day: -the automatic calculation was removed in 90cdc9163806f47f1e5f49897bd8e514913800b5 but no validation was set; -the help message became irrelevant; -the fiscal year end date was set as readonly in 52a8ed3c0c72b21baf589bc9b91a030d9da661a8 and not fixed in 3f4f77fd9d5c79c21665fa08d703bba7571decd8. --- addons/account/models/company.py | 23 ++++++++++++++++++++ addons/account/wizard/setup_wizards.py | 8 +++---- addons/account/wizard/setup_wizards_view.xml | 10 ++++----- 3 files changed, 32 insertions(+), 9 deletions(-) diff --git a/addons/account/models/company.py b/addons/account/models/company.py index 223c37eea7f..5ea0db1cd95 100644 --- a/addons/account/models/company.py +++ b/addons/account/models/company.py @@ -89,6 +89,22 @@ Best Regards,''')) account_invoice_onboarding_state = fields.Selection([('not_done', "Not done"), ('just_done', "Just done"), ('done', "Done"), ('closed', "Closed")], string="State of the account invoice onboarding panel", default='not_done') account_dashboard_onboarding_state = fields.Selection([('not_done', "Not done"), ('just_done', "Just done"), ('done', "Done"), ('closed', "Closed")], string="State of the account dashboard onboarding panel", default='not_done') + @api.constrains('account_opening_date', 'fiscalyear_last_day', 'fiscalyear_last_month') + def _check_fiscalyear_last_day(self): + # if the user explicitly chooses the 29th of February we allow it: + # there is no "fiscalyear_last_year" so we do not know his intentions. + if self.fiscalyear_last_day == 29 and self.fiscalyear_last_month == 2: + return + + if self.account_opening_date: + year = self.account_opening_date.year + else: + year = datetime.now().year + + max_day = calendar.monthrange(year, self.fiscalyear_last_month)[1] + if self.fiscalyear_last_day > max_day: + raise ValidationError(_("Invalid fiscal year last day")) + def get_and_update_account_invoice_onboarding_state(self): """ This method is called on the controller rendering method and ensures that the animations are displayed only one time. """ @@ -285,6 +301,7 @@ Best Regards,''')) def setting_init_fiscal_year_action(self): """ Called by the 'Fiscal Year Opening' button of the setup bar.""" company = self.env.user.company_id + company.create_op_move_if_non_existant() new_wizard = self.env['account.financial.year.op'].create({'company_id': company.id}) view_id = self.env.ref('account.setup_financial_year_opening_form').id @@ -339,10 +356,16 @@ Best Regards,''')) if not default_journal: raise UserError(_("Please install a chart of accounts or create a miscellaneous journal before proceeding.")) + today = datetime.today().date() + opening_date = today.replace(month=self.fiscalyear_last_month, day=self.fiscalyear_last_day) + timedelta(days=1) + if opening_date > today: + opening_date = opening_date + relativedelta(years=-1) + self.account_opening_move_id = self.env['account.move'].create({ 'name': _('Opening Journal Entry'), 'company_id': self.id, 'journal_id': default_journal.id, + 'date': opening_date, }) def opening_move_posted(self): diff --git a/addons/account/wizard/setup_wizards.py b/addons/account/wizard/setup_wizards.py index 75ee6d7c4fc..86ea724b667 100644 --- a/addons/account/wizard/setup_wizards.py +++ b/addons/account/wizard/setup_wizards.py @@ -11,23 +11,23 @@ class FinancialYearOpeningWizard(models.TransientModel): company_id = fields.Many2one(comodel_name='res.company', required=True) opening_move_posted = fields.Boolean(string='Opening Move Posted', compute='_compute_opening_move_posted') opening_date = fields.Date(string='Opening Date', required=True, related='company_id.account_opening_date', help="Date from which the accounting is managed in Odoo. It is the date of the opening entry.", readonly=False) - fiscalyear_last_day = fields.Integer(related="company_id.fiscalyear_last_day", required=True, - help="The last day of the month will be taken if the chosen day doesn't exist.") + fiscalyear_last_day = fields.Integer(related="company_id.fiscalyear_last_day", required=True, readonly=False, + help="Fiscal year last day.") fiscalyear_last_month = fields.Selection(selection=[(1, 'January'), (2, 'February'), (3, 'March'), (4, 'April'), (5, 'May'), (6, 'June'), (7, 'July'), (8, 'August'), (9, 'September'), (10, 'October'), (11, 'November'), (12, 'December')], related="company_id.fiscalyear_last_month", readonly=False, required=True, - help="The last day of the month will be taken if the chosen day doesn't exist.") + help="Fiscal year last month.") @api.depends('company_id.account_opening_move_id') def _compute_opening_move_posted(self): for record in self: record.opening_move_posted = record.company_id.opening_move_posted() - @api.multi def action_save_onboarding_fiscal_year(self): self.env.user.company_id.set_onboarding_step_done('account_setup_fy_data_state') + class SetupBarBankConfigWizard(models.TransientModel): _inherits = {'res.partner.bank': 'res_partner_bank_id'} _name = 'account.setup.bank.manual.config' diff --git a/addons/account/wizard/setup_wizards_view.xml b/addons/account/wizard/setup_wizards_view.xml index 1c9e21c8592..32eb0ae1c7e 100644 --- a/addons/account/wizard/setup_wizards_view.xml +++ b/addons/account/wizard/setup_wizards_view.xml @@ -8,23 +8,23 @@
-
+
-
+
-
+
Fiscal Year End
-
+
-
+