From 17b4d2cda2afbfcd9535affaac7ce6a505aee217 Mon Sep 17 00:00:00 2001 From: jffernandez Date: Wed, 3 Apr 2019 00:05:55 +0200 Subject: [PATCH] [11.0][FIX] l10n_es_account_invoice_sequence: Compute correct next number of sequence --- .../models/account_journal.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/l10n_es_account_invoice_sequence/models/account_journal.py b/l10n_es_account_invoice_sequence/models/account_journal.py index 0a1f3d2f8dc..b55a1fdaad9 100644 --- a/l10n_es_account_invoice_sequence/models/account_journal.py +++ b/l10n_es_account_invoice_sequence/models/account_journal.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- # Copyright 2011 NaN Projectes de Programari Lliure, S.L. # Copyright 2013-2017 Pedro M. Baeza +# Copyright 2019 Jose F. Fernandez from odoo import _, api, fields, exceptions, models @@ -46,7 +47,7 @@ def create(self, vals): return super(AccountJournal, self).create(vals) company = self.env['res.company'].browse(vals['company_id']) if company.chart_template_id.is_spanish_chart(): - journal = self.search([('company_id', '=', company.id)], limit=1) + journal = self._get_company_journal(company) if journal: vals['sequence_id'] = journal.sequence_id.id vals['refund_sequence'] = False @@ -57,3 +58,19 @@ def _get_invoice_types(self): 'sale', 'purchase', ] + + def _get_company_journal(self, company): + """Get an existing journal in the company to take it's counter.""" + if not company: + return False + return self.search([('company_id', '=', company.id)], limit=1) + + @api.model + def default_get(self, default_fields): + res = super(AccountJournal, self).default_get(default_fields) + company = self.env['res.company'].browse(res.get('company_id', False)) + if company.chart_template_id.is_spanish_chart(): + journal = self._get_company_journal(company) + if journal: + res['sequence_id'] = journal.sequence_id.id + return res