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

[FIX] point_of_sale: revert entry sign in tax report #161531

Closed
wants to merge 1 commit into from

Conversation

agr-odoo
Copy link
Contributor

With BE localization
Enable 'Use QR code on ticket' in Settings
Open POS Session
Add a Product with 21% Tax
Pay > Save QR link for later
Close Pos session
Access QR link, generate invoice
Check Accounting>Reporting>Tax Report

Issue: Line '03 - Operations subject to 21% VAT' will account twice
the product amount instead of canceling it

This occurs because when reverting the POS closing entry we create an
entry having amounts with inverted signs and same tax tags. We also need
to set the flag tax_tag_invert to ensure the amount correctly
accounted as reverse

opw-3815770
opw-3821017

@robodoo
Copy link
Contributor

robodoo commented Apr 11, 2024

@C3POdoo C3POdoo added the OE the report is linked to a support ticket (opw-...) label Apr 11, 2024
@agr-odoo agr-odoo force-pushed the 16.0-opw-3815770-fix-agr branch 3 times, most recently from 7193171 to 4601a39 Compare April 12, 2024 10:01
@agr-odoo agr-odoo marked this pull request as ready for review April 12, 2024 10:06
@agr-odoo
Copy link
Contributor Author

agr-odoo commented Apr 12, 2024

Hello @vin-odoo
If I'm not wrong you worked on this functionality so may I ask you a review?
I checked different solutions and replicating the behavior credit note seems a reasonable choice here

@C3POdoo C3POdoo requested review from a team and davidmonnom and removed request for a team April 12, 2024 10:12
@vin-odoo
Copy link
Contributor

@agr-odoo Hi!

I'd suggest checking with LAS or asking the accounting team for a review to be sure, and they can validate/ask him his opinion if needed/...
The fix seems to make sense, but I'd prefer for them to check 😉

(btw, it needs a test ^^)

@agr-odoo agr-odoo force-pushed the 16.0-opw-3815770-fix-agr branch 2 times, most recently from 0f1cca9 to f08442d Compare April 15, 2024 10:27
@agr-odoo agr-odoo requested review from smetl and removed request for davidmonnom April 15, 2024 10:28
invoice_product_line = invoice.line_ids.filtered(lambda line: line.display_type == 'product')
self.assertEqual(invoice_product_line.tax_tag_ids.name, 'invoice')
misc_product_line = misc_reversal_entry.line_ids.filtered(lambda line: line.display_type == 'product')
self.assertEqual(misc_product_line.tax_tag_ids.name, 'refund')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionally speaking, do we really want to use the refund tag on the reversal ? We revert it to redo it on an invoice, right, so it's not really a refund 🤔 IMO it would make sense to have the same repartition, hence same tag, but in negative (so, inverting the sign of the chosen tag(s)). But maybe I'm wrong, and I'm not a POS expert ; did you discuss that with a PO?

Copy link
Contributor Author

@agr-odoo agr-odoo Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We revert it to redo it on an invoice, right, so it's not really a refund

Conceptually seems the same of adding a credit note selecting 'Full refund and new draft invoice', so current patch results make sense to me, but I'm not an accountant :D
I'll check with a PO to be sure

Copy link
Contributor

@tsb-odoo tsb-odoo Apr 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not really if I understand it right.
In the "full refund and new draft invoice" flow, the original invoice, its refund and the new invoice can have three different accounting dates (I mean, possibly in 3 different months/quarters). Therefore, the refund has to be considered as such (a refund). Since, assuming no other entry elsewhere, it could result in a negative grid 03 in the month/quarter of the out_refund. >> Belgian Tax Report would be rejected upon submission to Intervat.

While in the PoS flow, the entry that cancels the initial booking and the invoice addressed to a specific customer will necessarily happen the same day and share the same accounting date.

Or am I missing something?

@@ -659,7 +659,7 @@ def _prepare_aml_values_list_per_nature(self):
if self.fiscal_position_id:
account = self.fiscal_position_id.map_account(account)

is_refund = line.qty * line.price_unit < 0
is_refund = -line.qty * line.price_unit < 0
Copy link
Contributor

@smetl smetl Apr 19, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are breaking everything with that. Let's start from the beginning:

The line of a pos order are already signed (+ for a sale, - for a refund (negative quantity)).
It's a refund if the line is negative so this line is completely correct, remove your diff!

Below (L671), you see quantity=-line.qty,. This is because for a sale, the product and tax lines need accounting journal items in credit.

When asking for an invoice after the closing of the POS entry, you enter _create_misc_reversal_move (L801).
In this method, we call _prepare_aml_values_list_per_nature and then we reverse the accounting amounts.
Here is the error!
The refund is not considered as a refund since the pos order is always the same.
Instead, add an extra sign=1 parameter (named that way because there is one in the following versions because of Mexico).
Then:
is_refund = line.qty * line.price_unit * sign < 0
and
quantity=-line.qty * sign,
and you can remove the reverse of accounting amounts:

aml_values['balance'] = -aml_values['balance']
aml_values['amount_currency'] = -aml_values['amount_currency']

and call _prepare_aml_values_list_per_nature with sign=-1 instead

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@agr-odoo Forget everything in the comment above. Instead, let's force the inverse_tax_tags field as:
inverse_tax_tags = not is_refund

On the 2 loops below, force this value (L684 & L704):

        # Create the tax lines
        for tax_line_vals in tax_results['tax_lines_to_add']:
            tax_rep = self.env['account.tax.repartition.line'].browse(tax_line_vals['tax_repartition_line_id'])
            amount_currency = tax_line_vals['tax_amount']
            balance = company_currency.round(amount_currency * rate)
            aml_vals_list_per_nature['tax'].append({
                'name': tax_rep.tax_id.name,
                'account_id': tax_line_vals['account_id'],
                'partner_id': tax_line_vals['partner_id'],
                'currency_id': tax_line_vals['currency_id'],
                'tax_repartition_line_id': tax_line_vals['tax_repartition_line_id'],
                'tax_ids': tax_line_vals['tax_ids'],
                'tax_tag_ids': tax_line_vals['tax_tag_ids'],
                'group_tax_id': None if tax_rep.tax_id.id == tax_line_vals['tax_id'] else tax_line_vals['tax_id'],
                'amount_currency': amount_currency,
                'balance': balance,
                'inverse_tax_tags': inverse_tax_tags, # <- HERE
            })
            total_amount_currency += amount_currency
            total_balance += balance
        # Create the aml values for order lines.
        for base_line_vals, update_base_line_vals in tax_results['base_lines_to_update']:
            order_line = base_line_vals['record']
            amount_currency = update_base_line_vals['price_subtotal']
            balance = company_currency.round(amount_currency * rate)
            aml_vals_list_per_nature['product'].append({
                'name': order_line.full_product_name,
                'account_id': base_line_vals['account'].id,
                'partner_id': base_line_vals['partner'].id,
                'currency_id': base_line_vals['currency'].id,
                'tax_ids': [(6, 0, base_line_vals['taxes'].ids)],
                'tax_tag_ids': update_base_line_vals['tax_tag_ids'],
                'amount_currency': amount_currency,
                'balance': balance,
                'inverse_tax_tags': inverse_tax_tags, # <- HERE
            })
            total_amount_currency += amount_currency
            total_balance += balance

With BE localization
Enable 'Use QR code on ticket' in Settings
Open POS Session
Add a Product with 21% Tax
Pay > Save QR link for later
Close Pos session
Access QR link, generate invoice
Check Accounting>Reporting>Tax Report

Issue: Line '03 - Operations subject to 21% VAT' will account twice
the product amount instead of canceling it

This occurs because when reverting the POS closing entry we create an
entry having amounts with inverted signs but same tax tags as the
original invoice.

opw-3815770
opw-3821017
opw-3869363

Co-authored-by: Laurent Smet (las) <las@odoo.com>
@smetl
Copy link
Contributor

smetl commented Apr 26, 2024

@robodoo r+

robodoo pushed a commit that referenced this pull request Apr 26, 2024
With BE localization
Enable 'Use QR code on ticket' in Settings
Open POS Session
Add a Product with 21% Tax
Pay > Save QR link for later
Close Pos session
Access QR link, generate invoice
Check Accounting>Reporting>Tax Report

Issue: Line '03 - Operations subject to 21% VAT' will account twice
the product amount instead of canceling it

This occurs because when reverting the POS closing entry we create an
entry having amounts with inverted signs but same tax tags as the
original invoice.

opw-3815770
opw-3821017
opw-3869363

closes #161531

Signed-off-by: Laurent Smet (las) <las@odoo.com>
Co-authored-by: Laurent Smet (las) <las@odoo.com>
@robodoo robodoo closed this Apr 26, 2024
MohammedBasioni pushed a commit to odoo-dev/odoo that referenced this pull request Apr 29, 2024
With BE localization
Enable 'Use QR code on ticket' in Settings
Open POS Session
Add a Product with 21% Tax
Pay > Save QR link for later
Close Pos session
Access QR link, generate invoice
Check Accounting>Reporting>Tax Report

Issue: Line '03 - Operations subject to 21% VAT' will account twice
the product amount instead of canceling it

This occurs because when reverting the POS closing entry we create an
entry having amounts with inverted signs but same tax tags as the
original invoice.

opw-3815770
opw-3821017
opw-3869363

closes odoo#161531

Signed-off-by: Laurent Smet (las) <las@odoo.com>
Co-authored-by: Laurent Smet (las) <las@odoo.com>
@fw-bot
Copy link
Contributor

fw-bot commented Apr 30, 2024

@agr-odoo @smetl this pull request has forward-port PRs awaiting action (not merged or closed):

2 similar comments
@fw-bot
Copy link
Contributor

fw-bot commented May 1, 2024

@agr-odoo @smetl this pull request has forward-port PRs awaiting action (not merged or closed):

@fw-bot
Copy link
Contributor

fw-bot commented May 2, 2024

@agr-odoo @smetl this pull request has forward-port PRs awaiting action (not merged or closed):

@fw-bot
Copy link
Contributor

fw-bot commented May 3, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OE the report is linked to a support ticket (opw-...)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants