Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
37
account_move_line_purchase_info/migrations/18.0.2.0.0/post-migration.py
Executable file
37
account_move_line_purchase_info/migrations/18.0.2.0.0/post-migration.py
Executable file
@@ -0,0 +1,37 @@
|
||||
import logging
|
||||
|
||||
from odoo import SUPERUSER_ID, api
|
||||
|
||||
_logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def migrate(cr, version):
|
||||
env = api.Environment(cr, SUPERUSER_ID, {})
|
||||
purchase_orders = env["purchase.order"].search([("state", "=", "purchase")])
|
||||
for order in purchase_orders:
|
||||
try:
|
||||
_logger.info(f"Processing Purchase Order: {order.name} (ID: {order.id})")
|
||||
valued_lines = order.order_line.invoice_lines.filtered(
|
||||
lambda line: line.product_id
|
||||
and line.product_id.cost_method != "standard"
|
||||
and (
|
||||
not line.company_id.tax_lock_date
|
||||
or line.date > line.company_id.tax_lock_date
|
||||
)
|
||||
)
|
||||
svls, _amls = valued_lines._apply_price_difference()
|
||||
|
||||
if svls:
|
||||
svls._validate_accounting_entries()
|
||||
|
||||
bills = order.invoice_ids.filtered(lambda bill: bill.state == "posted")
|
||||
bills._stock_account_anglo_saxon_reconcile_valuation()
|
||||
|
||||
except Exception as e:
|
||||
_logger.error(
|
||||
(
|
||||
f"Error processing Purchase Order {order.name} "
|
||||
f"(ID: {order.id}): {str(e)}"
|
||||
),
|
||||
exc_info=True,
|
||||
)
|
||||
30
account_move_line_purchase_info/migrations/18.0.2.0.0/pre-migration.py
Executable file
30
account_move_line_purchase_info/migrations/18.0.2.0.0/pre-migration.py
Executable file
@@ -0,0 +1,30 @@
|
||||
from openupgradelib import openupgrade
|
||||
|
||||
|
||||
def migrate(cr, version):
|
||||
openupgrade.logged_query(
|
||||
cr,
|
||||
"""
|
||||
ALTER TABLE account_move_line
|
||||
ADD COLUMN IF NOT EXISTS oca_purchase_line_id INTEGER;
|
||||
""",
|
||||
)
|
||||
|
||||
openupgrade.logged_query(
|
||||
cr,
|
||||
"""
|
||||
UPDATE account_move_line
|
||||
SET oca_purchase_line_id = purchase_line_id;
|
||||
""",
|
||||
)
|
||||
|
||||
openupgrade.logged_query(
|
||||
cr,
|
||||
"""
|
||||
UPDATE account_move_line
|
||||
SET purchase_line_id = NULL
|
||||
FROM account_move
|
||||
WHERE account_move_line.move_id = account_move.id
|
||||
AND account_move.move_type = 'entry';
|
||||
""",
|
||||
)
|
||||
Reference in New Issue
Block a user