Skip to content

Commit

Permalink
T0718 FIX sponsorship products and pricelists migration
Browse files Browse the repository at this point in the history
- Move migration script in relevant module
- FIX data for migration
  • Loading branch information
ecino committed Feb 5, 2024
1 parent 75253ae commit 60448b6
Show file tree
Hide file tree
Showing 7 changed files with 280 additions and 14 deletions.
15 changes: 1 addition & 14 deletions partner_compassion/views/partner_compassion_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
<record id="view_partner_form_compassion_birthdate" model="ir.ui.view">
<field name="name">res.partner.form.compassion.personal.info</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="partner_personal_info.view_partner_form_compassion_birthdate"/>
<field name="inherit_id" ref="partner_personal_info.view_partner_form_compassion_personal"/>
<field name="arch" type="xml">
<field name="birthdate_date" position="after">
<field name="deathdate" attrs="{'invisible': [('is_company','=',True)]}"/>
Expand All @@ -50,16 +50,6 @@
<field name="partner_latitude"/>
<field name="partner_longitude"/>
</group>
<separator string="Data protection policy agreement" colspan="2"/>
<field name="privacy_statement_ids"
context="{'default_partner_id': active_id}" groups="child_compassion.group_sponsorship">
<tree>
<field name="version"/>
<field name="agreement_date"/>
<field name="origin_signature"/>
<button name="open_contract" type="object" icon="fa-external-link"/>
</tree>
</field>
</group>
</field>
</record>
Expand Down Expand Up @@ -97,9 +87,6 @@
<attribute name="invisible">1</attribute>
</xpath>

<!-- Move privacy statement field -->
<page name="privacy_data" position="replace"/>

<!-- Church unlinked -->
<field name="church_id" position="after">
<field name="church_unlinked"
Expand Down
2 changes: 2 additions & 0 deletions sponsorship_switzerland/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,11 @@
"demo": ["data/demo_journal.xml", "data/demo_account.xml"],
"data": [
"data/product.xml",
"data/pricelists.xml",
"data/completion_rules.xml",
"data/sequence.xml",
"data/partner_category_data.xml",
"data/payment_modes.xml",
"security/ir.model.access.csv",
"views/res_partner_view.xml",
"views/contract_view.xml",
Expand Down
100 changes: 100 additions & 0 deletions sponsorship_switzerland/data/payment_modes.xml
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>
33 changes: 33 additions & 0 deletions sponsorship_switzerland/data/pricelists.xml
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>
74 changes: 74 additions & 0 deletions sponsorship_switzerland/data/product.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,80 @@
Resource: product.template
-->
<data noupdate="1">
<!-- Sponsorship templates -->
<record id="product_template_sponsorship" model="product.template">
<field name="name">Sponsorship</field>
<field name="type">service</field>
<field name="categ_id" ref="sponsorship_compassion.product_category_sponsorship" />
<field name="list_price">42</field>
<field name="property_account_income_id" search="[('code','=','6000')]"/>
<field name="property_account_expense_id" search="[('code','=','5000')]"/>
<field name="default_code">sponsorship</field>
</record>
<record id="product_template_sponsorship_ldp" model="product.template">
<field name="name">LDP Sponsorship</field>
<field name="categ_id" ref="sponsorship_compassion.product_category_sponsorship"/>
<field name="list_price">310</field>
<field name="type">service</field>
<field name="description">Sponsorship for LDP Students.</field>
<field name="property_account_income_id" search="[('code','=','6013')]"/>
<field name="property_account_expense_id" search="[('code','=','5000')]"/>
<field name="default_code">sponsorship_ldp</field>
</record>
<record id="product_template_fund_gen" model="product.template">
<field name="name">General Fund</field>
<field name="type">service</field>
<field name="categ_id" ref="sponsorship_compassion.product_category_fund" />
<field name="list_price">42</field>
<field name="description">Thanks to your donation to the General Fund, through your help we can offer
a concrete help and a new future to many children on the field and restore hope in their lives.</field>
<field name="property_account_income_id" search="[('code','=','6004')]"/>
<field name="property_account_expense_id" search="[('code','=','5000')]"/>
<field name="default_code">fund_gen</field>
</record>

<!-- Sponsorship Gifts Templates -->
<record id="product_template_gift_birthday" model="product.template">
<field name="name">Birthday Gift</field>
<field name="type">service</field>
<field name="categ_id" ref="sponsorship_compassion.product_category_gift" />
<field name="property_account_income_id" search="[('code','=','6003')]" />
<field name="property_account_expense_id" search="[('code','=','5000')]" />
<field name="default_code">gift_birthday</field>
</record>
<record id="product_template_gift_gen" model="product.template">
<field name="name">General Gift</field>
<field name="type">service</field>
<field name="categ_id" ref="sponsorship_compassion.product_category_gift" />
<field name="property_account_income_id" search="[('code','=','6003')]" />
<field name="property_account_expense_id" search="[('code','=','5000')]" />
<field name="default_code">gift_gen</field>
</record>
<record id="product_template_gift_family" model="product.template">
<field name="name">Family Gift</field>
<field name="type">service</field>
<field name="categ_id" ref="sponsorship_compassion.product_category_gift" />
<field name="property_account_income_id" search="[('code','=','6003')]" />
<field name="property_account_expense_id" search="[('code','=','5000')]" />
<field name="default_code">gift_family</field>
</record>
<record id="product_template_gift_project" model="product.template">
<field name="name">Project Gift</field>
<field name="type">service</field>
<field name="categ_id" ref="sponsorship_compassion.product_category_gift" />
<field name="property_account_income_id" search="[('code','=','6003')]" />
<field name="property_account_expense_id" search="[('code','=','5000')]" />
<field name="default_code">gift_project</field>
</record>
<record id="product_template_gift_graduation" model="product.template">
<field name="name">Graduation Gift</field>
<field name="type">service</field>
<field name="categ_id" ref="sponsorship_compassion.product_category_gift" />
<field name="property_account_income_id" search="[('code','=','6003')]" />
<field name="property_account_expense_id" search="[('code','=','5000')]" />
<field name="default_code">gift_graduation</field>
</record>

<!-- Funds templates -->
<record id="product_template_fund_aid" model="product.template">
<field name="name">AIDS/HIV Fund</field>
Expand Down
57 changes: 57 additions & 0 deletions sponsorship_switzerland/migrations/14.0.1.0.0/post-migration.py
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 sponsorship_switzerland/migrations/14.0.1.0.0/pre-migration.py
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"),
])

0 comments on commit 60448b6

Please sign in to comment.