Skip to content

Commit

Permalink
[FIX] l10n_br: Make sure credit notes use same sequence as invoices
Browse files Browse the repository at this point in the history
Bugfix.
Steps to reproduce:
1. Create a fresh DB with the Brazilian localization.
2. Create a new Credit Note (directly from the menu, not from an
   invoice). Confirm.
3. Observe that you get a ValidationError: "Another entry with the same
   name already exists." because the name of the Credit Note is
   NFe 00000001, and an invoice called NFe 00000001 already exists.

Analysis:
The credit note should be called NFe 00000002, because in Brazil the
same sequences should be used both for invoices and for credit notes of
a given document type.
However, because the `refund_sequence` field is set to True on the
'Customer Invoices' journal, the sequence mixin doesn't consider
invoices and credit notes as using the same sequence, and therefore
doesn't consider the existing invoice when finding a new name for the
credit note.

Solution:
Set the field `refund_sequence` to False on the journal created by the
l10n_br template.
We also take the opportunity to move the code that provides a default
name to the demo invoices to a separate file demo/account_demo.py, for
consistency with other localizations.

closes odoo#137700

Signed-off-by: Josse Colpaert <jco@odoo.com>
  • Loading branch information
antoine162 committed Oct 6, 2023
1 parent 2a4bdce commit dc3a099
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 16 deletions.
1 change: 1 addition & 0 deletions addons/l10n_br/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import demo
from . import models
from . import wizard
1 change: 1 addition & 0 deletions addons/l10n_br/demo/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import account_demo
20 changes: 20 additions & 0 deletions addons/l10n_br/demo/account_demo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, api


class AccountChartTemplate(models.AbstractModel):
_inherit = 'account.chart.template'

@api.model
def _get_demo_data_move(self, company=False):
""" Set the l10n_latam_document_number on demo invoices """
move_data = super()._get_demo_data_move(company)
if company.account_fiscal_country_id.code == 'BR':
number = 0
for move in move_data.values():
# vendor bills must be manually numbered (l10n_br uses the standard AccountMove._is_manual_document_number())
if move['move_type'] == 'in_invoice':
move['l10n_latam_document_number'] = f'{number:08d}'
number += 1

return move_data
20 changes: 5 additions & 15 deletions addons/l10n_br/models/template_br.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models, api
from odoo import models
from odoo.addons.account.models.chart_template import template


Expand Down Expand Up @@ -39,18 +39,8 @@ def _get_br_res_company(self):
@template('br', 'account.journal')
def _get_br_account_journal(self):
return {
'sale': {'l10n_br_invoice_serial': '1'},
'sale': {
'l10n_br_invoice_serial': '1',
'refund_sequence': False,
},
}

@api.model
def _get_demo_data_move(self, company=False):
move_data = super()._get_demo_data_move(company)
if company.account_fiscal_country_id.code == 'BR':
number = 0
for move in move_data.values():
# vendor bills must be manually numbered (l10n_br uses the standard AccountMove._is_manual_document_number())
if move['move_type'] == 'in_invoice':
move['l10n_latam_document_number'] = f'{number:08d}'
number += 1

return move_data
2 changes: 1 addition & 1 deletion addons/l10n_br/views/account_journal_views.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<field name="name">account.journal.form</field>
<field name="inherit_id" ref="l10n_latam_invoice_document.view_account_journal_form"/>
<field name="arch" type="xml">
<field name="type" position="after">
<field name="type" position="after">
<field name="l10n_br_invoice_serial" invisible="not l10n_latam_use_documents or country_code != 'BR'"/>
</field>
</field>
Expand Down

0 comments on commit dc3a099

Please sign in to comment.