-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
T0718 FIX sponsorship products and pricelists migration
- Move migration script in relevant module - FIX data for migration
- Loading branch information
Showing
7 changed files
with
280 additions
and
14 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
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,100 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<odoo> | ||
<!-- Mandatory journals --> | ||
<record id="journal_raif" model="account.journal"> | ||
<field name="name">Raiffeisen Current Account CHF</field> | ||
<field name="code">RCC</field> | ||
<field name="type">bank</field> | ||
<!-- <field name="inbound_payment_method_ids" eval="[(4, ref('l10n_ch_pain_direct_debit.export_sepa_dd'))]"/>--> | ||
</record> | ||
<record id="journal_post" model="account.journal"> | ||
<field name="name">Postfinance CHF</field> | ||
<field name="code">CCP</field> | ||
<field name="type">bank</field> | ||
<!-- <field name="inbound_payment_method_ids" eval="[(4, ref('l10n_ch_pain_direct_debit.export_sepa_dd'))]"/>--> | ||
</record> | ||
|
||
<!-- BVR --> | ||
<record id="payment_mode_bvr" model="account.payment.mode"> | ||
<field name="name">BVR</field> | ||
<field name="active" eval="True"/> | ||
<field name="payment_method_id" ref="account.account_payment_method_manual_in"/> | ||
<field name="payment_type">inbound</field> | ||
<field name="payment_order_ok" eval="False"/> | ||
<field name="bank_account_link">variable</field> | ||
</record> | ||
|
||
<!-- LSV --> | ||
<record id="payment_mode_lsv" model="account.payment.mode"> | ||
<field name="name">LSV</field> | ||
<field name="active" eval="True"/> | ||
<!-- <field name="payment_method_id" ref="l10n_ch_pain_direct_debit.export_sepa_dd"/>--> | ||
<field name="payment_type">inbound</field> | ||
<field name="payment_order_ok" eval="True"/> | ||
<field name="bank_account_link">fixed</field> | ||
<field name="fixed_journal_id" ref="journal_raif"/> | ||
<field name="group_lines" eval="True"/> | ||
</record> | ||
<record id="payment_mode_lsv_25th" model="account.payment.mode"> | ||
<field name="name">LSV 25th</field> | ||
<field name="active" eval="True"/> | ||
<!-- <field name="payment_method_id" ref="l10n_ch_pain_direct_debit.export_sepa_dd"/>--> | ||
<field name="payment_type">inbound</field> | ||
<field name="payment_order_ok" eval="True"/> | ||
<field name="bank_account_link">fixed</field> | ||
<field name="fixed_journal_id" ref="journal_raif"/> | ||
<field name="group_lines" eval="True"/> | ||
</record> | ||
<record id="payment_mode_lsv_multi_months" model="account.payment.mode"> | ||
<field name="name">LSV multi-months</field> | ||
<field name="active" eval="True"/> | ||
<!-- <field name="payment_method_id" ref="l10n_ch_pain_direct_debit.export_sepa_dd"/>--> | ||
<field name="payment_type">inbound</field> | ||
<field name="payment_order_ok" eval="True"/> | ||
<field name="bank_account_link">fixed</field> | ||
<field name="fixed_journal_id" ref="journal_raif"/> | ||
<field name="group_lines" eval="True"/> | ||
</record> | ||
|
||
<!-- Postfinance DD --> | ||
<record id="payment_mode_postfinance_dd" model="account.payment.mode"> | ||
<field name="name">Postfinance Direct Debit</field> | ||
<field name="active" eval="True"/> | ||
<!-- <field name="payment_method_id" ref="l10n_ch_pain_direct_debit.export_sepa_dd"/>--> | ||
<field name="payment_type">inbound</field> | ||
<field name="payment_order_ok" eval="True"/> | ||
<field name="bank_account_link">fixed</field> | ||
<field name="fixed_journal_id" ref="journal_post"/> | ||
<field name="group_lines" eval="True"/> | ||
</record> | ||
<record id="payment_mode_postfinance_dd_25th" model="account.payment.mode"> | ||
<field name="name">Postfinance Direct Debit 25th</field> | ||
<field name="active" eval="True"/> | ||
<!-- <field name="payment_method_id" ref="l10n_ch_pain_direct_debit.export_sepa_dd"/>--> | ||
<field name="payment_type">inbound</field> | ||
<field name="payment_order_ok" eval="True"/> | ||
<field name="bank_account_link">fixed</field> | ||
<field name="fixed_journal_id" ref="journal_post"/> | ||
<field name="group_lines" eval="True"/> | ||
</record> | ||
<record id="payment_mode_postfinance_dd_multi_months" model="account.payment.mode"> | ||
<field name="name">Postfinance Direct Debit multi-months</field> | ||
<field name="active" eval="True"/> | ||
<!-- <field name="payment_method_id" ref="l10n_ch_pain_direct_debit.export_sepa_dd"/>--> | ||
<field name="payment_type">inbound</field> | ||
<field name="payment_order_ok" eval="True"/> | ||
<field name="bank_account_link">fixed</field> | ||
<field name="fixed_journal_id" ref="journal_post"/> | ||
<field name="group_lines" eval="True"/> | ||
</record> | ||
|
||
<!-- Ordre permanent --> | ||
<record id="payment_mode_permanent_order" model="account.payment.mode"> | ||
<field name="name">Permanent Order</field> | ||
<field name="active" eval="True"/> | ||
<field name="payment_method_id" ref="account.account_payment_method_manual_in"/> | ||
<field name="payment_type">inbound</field> | ||
<field name="payment_order_ok" eval="False"/> | ||
<field name="bank_account_link">variable</field> | ||
</record> | ||
</odoo> |
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,33 @@ | ||
<odoo> | ||
<data noupdate="1"> | ||
<record id="pricelist_item_sponsorship" model="product.pricelist.item"> | ||
<field name="pricelist_id" ref="product.list0"/> | ||
<field name="applied_on">1_product</field> | ||
<field name="product_tmpl_id" ref="product_template_sponsorship"/> | ||
<field name="compute_price">fixed</field> | ||
<field name="fixed_price">42.0</field> | ||
</record> | ||
<record id="pricelist_item_gen" model="product.pricelist.item"> | ||
<field name="pricelist_id" ref="product.list0"/> | ||
<field name="applied_on">1_product</field> | ||
<field name="product_tmpl_id" ref="product_template_fund_gen"/> | ||
<field name="compute_price">fixed</field> | ||
<field name="fixed_price">8.0</field> | ||
</record> | ||
<!-- TODO T0488 update product ref --> | ||
<record id="pricelist_item_csp" model="product.pricelist.item"> | ||
<field name="pricelist_id" ref="product.list0"/> | ||
<field name="applied_on">1_product</field> | ||
<field name="product_tmpl_id" search="[('name','=','Survival Sponsorships')]"/> | ||
<field name="compute_price">fixed</field> | ||
<field name="fixed_price">62.0</field> | ||
</record> | ||
<record id="pricelist_item_ldp" model="product.pricelist.item"> | ||
<field name="pricelist_id" ref="product.list0"/> | ||
<field name="applied_on">1_product</field> | ||
<field name="product_tmpl_id" ref="product_template_sponsorship_ldp"/> | ||
<field name="compute_price">fixed</field> | ||
<field name="fixed_price">310.0</field> | ||
</record> | ||
</data> | ||
</odoo> |
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
57 changes: 57 additions & 0 deletions
57
sponsorship_switzerland/migrations/14.0.1.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,57 @@ | ||
import logging | ||
|
||
from dateutil.utils import today | ||
from openupgradelib import openupgrade | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
# Set default pricelist to all contracts | ||
openupgrade.logged_query(env.cr, """ | ||
UPDATE recurring_contract | ||
SET pricelist_id = 1 | ||
WHERE pricelist_id IS NULL; | ||
""") | ||
# Retrieve balance product | ||
balance_product = env["product.product"].search([("name", "=", "Balance")]) | ||
if len(balance_product.ids) != 1: | ||
_logger.warning("balance product is not unique") | ||
return 1 | ||
# retrieve all contract line | ||
contract_lines = env["recurring.contract"].search([("state", "not in", ["cancelled", "terminated"])]).mapped( | ||
"contract_line_ids") | ||
standard_prices = {} | ||
for contract_line in contract_lines: | ||
# Calculated the correct price of a line | ||
product = contract_line.product_id | ||
if not product.pricelist_id: | ||
continue | ||
if product.id not in standard_prices: | ||
standard_prices[product.id] = product.pricelist_id.get_product_price( | ||
product, 1, contract_line.contract_id.partner_id, today()) | ||
expected_price = standard_prices[product.id] | ||
# if there's a difference we balance it in a new line | ||
if contract_line.amount != expected_price and product.pricelist_item_count > 0: | ||
balance_price = contract_line.amount - expected_price | ||
# Try to find an existing balance line of a contract | ||
balance_line = contract_line.contract_id.contract_line_ids.filtered( | ||
lambda l: l.product_id == balance_product) | ||
# we had the balance amount if a balance line exist or we create the balance line | ||
if balance_line: | ||
_logger.info( | ||
f"Balance contract line found old amount: {balance_line.amount}, for contract {contract_line.contract_id}") | ||
balance_line.write({"amount": balance_line.amount + balance_price}) | ||
_logger.info( | ||
f"Balance contract line populated new amount: {balance_line.amount}, for contract {contract_line.contract_id}") | ||
else: | ||
balance_line = env["recurring.contract.line"].create({ | ||
"amount": balance_price, | ||
"product_id": balance_product.id, | ||
"quantity": 1, | ||
"contract_id": contract_line.contract_id.id | ||
}) | ||
_logger.info(f"Balance contract line created {balance_line} for contract {contract_line.contract_id}") | ||
contract_line.write({"amount": expected_price}) | ||
_logger.info("Migration done!") |
13 changes: 13 additions & 0 deletions
13
sponsorship_switzerland/migrations/14.0.1.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,13 @@ | ||
from openupgradelib import openupgrade | ||
|
||
def migrate(cr, version): | ||
openupgrade.rename_xmlids(cr, [ | ||
("sponsorship_compassion.product_template_sponsorship", "sponsorship_switzerland.product_template_sponsorship"), | ||
("sponsorship_compassion.product_template_sponsorship_ldp", "sponsorship_switzerland.product_template_sponsorship_ldp"), | ||
("sponsorship_compassion.product_template_fund_gen", "sponsorship_switzerland.product_template_fund_gen"), | ||
("sponsorship_compassion.product_template_gift_birthday", "sponsorship_switzerland.product_template_gift_birthday"), | ||
("sponsorship_compassion.product_template_gift_gen", "sponsorship_switzerland.product_template_gift_gen"), | ||
("sponsorship_compassion.product_template_gift_family", "sponsorship_switzerland.product_template_gift_family"), | ||
("sponsorship_compassion.product_template_gift_project", "sponsorship_switzerland.product_template_gift_project"), | ||
("sponsorship_compassion.product_template_gift_graduation", "sponsorship_switzerland.product_template_gift_graduation"), | ||
]) |