Skip to content

Commit

Permalink
[11.0][FIX] l10n_es_account_invoice_sequence: Compute correct next nu…
Browse files Browse the repository at this point in the history
…mber of sequence
  • Loading branch information
jffernandez committed Apr 24, 2019
1 parent 36a13ec commit 17b4d2c
Showing 1 changed file with 18 additions and 1 deletion.
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

0 comments on commit 17b4d2c

Please sign in to comment.