-
-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] account_invoice_margin_sale: Update purchase cost in invoice li…
…nes from sale order when installing module
- Loading branch information
1 parent
012c35e
commit c5e426d
Showing
6 changed files
with
42 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). | ||
|
||
from .hooks import post_init_hook | ||
from . import models |
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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
def pre_init_hook(cr, registry): | ||
# update purchase_price for invoices from sale_order | ||
cr.execute( | ||
""" | ||
UPDATE account_move_line AS aml | ||
SET purchase_price = ( | ||
SELECT COALESCE(SUM(sol.purchase_price), 0.0) | ||
FROM sale_order_line AS sol | ||
INNER JOIN sale_order_line_invoice_rel AS rel | ||
ON rel.order_line_id = sol.id | ||
WHERE rel.invoice_line_id = aml.id | ||
); | ||
""" | ||
) | ||
# recalculate margin for invoices from sale_order | ||
cr.execute( | ||
""" | ||
WITH aml AS ( | ||
SELECT | ||
account_move_line.move_id, | ||
SUM(account_move_line.margin) AS sum_margin, | ||
SUM(account_move_line.margin_signed) AS sum_margin_signed | ||
FROM account_move_line | ||
INNER JOIN account_move ON account_move.id = account_move_line.move_id | ||
INNER JOIN sale_order_line_invoice_rel AS rel | ||
ON rel.invoice_line_id = aml.id | ||
GROUP BY account_move_line.move_id | ||
) | ||
UPDATE account_move | ||
SET margin = aml.sum_margin, | ||
margin_signed = aml.sum_margin_signed, | ||
margin_percent = aml.sum_margin_signed / amount_untaxed * 100 | ||
FROM aml | ||
WHERE account_move.id = aml.move_id | ||
AND account_move.amount_untaxed > 0.0; | ||
""" | ||
) |
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