-
-
Notifications
You must be signed in to change notification settings - Fork 693
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] account_global_discount: More on global discount/taxes link
- We need to take into account invoice lines with multiple taxes, so the link should be m2m. - Migration scripts for preserving the best information on existing installations. - Tests for checking new conditions. - Perform sanity check for not ending in an incompatible situation. - Some refactor done on onchanges for avoiding duplicating operations. - Adjust UI for not allowing to edit computed invoice global discounts.
- Loading branch information
1 parent
d2f508a
commit a6d211d
Showing
9 changed files
with
238 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
account_global_discount/migrations/11.0.2.0.0/post-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
# Copyright 2020 Tecnativa - Pedro M. Baeza | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from openupgradelib import openupgrade # pylint: disable=W7936 | ||
from psycopg2 import sql | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
# Link the new field that points to the invoice global discount instead | ||
# of the global discount definition | ||
openupgrade.logged_query( | ||
env.cr, sql.SQL(""" | ||
UPDATE account_move_line aml | ||
SET invoice_global_discount_id = aigd.id | ||
FROM account_invoice_global_discount aigd | ||
WHERE aigd.invoice_id = aml.invoice_id | ||
AND aigd.global_discount_id = aml.{} | ||
""").format( | ||
sql.Identifier(openupgrade.get_legacy_name("global_discount_id")) | ||
) | ||
) | ||
# Link to existing global discount records, all the invoice taxes as best | ||
# effort | ||
openupgrade.logged_query( | ||
env.cr, """ | ||
INSERT INTO account_invoice_global_discount_account_tax_rel | ||
(account_invoice_global_discount_id, account_tax_id) | ||
SELECT aigd.id, ailt.tax_id | ||
FROM account_invoice_global_discount aigd | ||
JOIN account_invoice_line ail ON aigd.invoice_id = ail.invoice_id | ||
JOIN account_invoice_line_tax ailt ON ailt.invoice_line_id = ail.id | ||
GROUP BY aigd.id, ailt.tax_id""" | ||
) | ||
# Delete in prevention of manual manipulations existing tax lines linked | ||
# to global discount journal items | ||
openupgrade.logged_query( | ||
env.cr, """ | ||
DELETE FROM account_move_line_account_tax_rel rel | ||
USING account_move_line aml | ||
WHERE rel.account_move_line_id = aml.id | ||
AND aml.invoice_global_discount_id IS NOT NULL""" | ||
) | ||
# Link all invoice taxes in global discount existing journal items as best | ||
# effort | ||
openupgrade.logged_query( | ||
env.cr, """ | ||
INSERT INTO account_move_line_account_tax_rel | ||
(account_move_line_id, account_tax_id) | ||
SELECT aml.id, rel.account_tax_id | ||
FROM account_move_line aml | ||
JOIN account_invoice_global_discount_account_tax_rel rel | ||
ON rel.account_invoice_global_discount_id = | ||
aml.invoice_global_discount_id""" | ||
) |
11 changes: 11 additions & 0 deletions
11
account_global_discount/migrations/11.0.2.0.0/pre-migration.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Copyright 2020 Tecnativa - Pedro M. Baeza | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from openupgradelib import openupgrade # pylint: disable=W7936 | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
openupgrade.rename_columns( | ||
env.cr, {"account_move_line": [("global_discount_id", None)]} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
* Global Discount move lines are created for a common base amount. If that | ||
wasn't the case, we should split discount move lines between bases and | ||
assign proper taxes accordingly. | ||
* Not all the taxes combination can be compatible with global discounts, as | ||
the generated journal items won't be correct for taxes declarations. An error | ||
is raised in that cases. | ||
* Currently, taxes in invoice lines are mandatory with global discounts. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.