Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.0][FIX] l10n_es_account_invoice_sequence: Compute correct next number of sequence #1052

Merged
merged 1 commit into from
Apr 26, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion l10n_es_account_invoice_sequence/models/account_journal.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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