server-tools icon indicating copy to clipboard operation
server-tools copied to clipboard

[18.0][MIG] iap_alternative_provider: Migration to 18.0

Open natuan9 opened this issue 9 months ago • 1 comments

Change:

  • This commit makes the Service field required, so the Service should be set when the Provider is changed rather than when creating the IAP Account

natuan9 avatar Mar 28 '25 03:03 natuan9

Can we better insert commit of auto pre-commit before the migration commit?

kobros-tech avatar Mar 31 '25 21:03 kobros-tech

@kobros-tech can you please review the requested changes? approval is hanging since there is a pending review.

hussain avatar May 12 '25 14:05 hussain

This PR has the approved label and has been created more than 5 days ago. It should therefore be ready to merge by a maintainer (or a PSC member if the concerned addon has no declared maintainer). 🤖

OCA-git-bot avatar May 12 '25 18:05 OCA-git-bot

Not sure if this belongs into a particular iap_account implementation but regarding _set_service_from_provider() I see a similar issue with the state not being "registered".

In my specific case, the account of an alternative provider (ClickSend) uses (always) the "sms" service. If the state is not "registered" there will always be the message "You cannot send SMS while your account is not registered" with a link to Odoo registration. That's even shown in the create form on the fly.

So at the moment I have to do this:

from odoo import fields, models, api

class IapAccount(models.Model):
    _inherit = "iap.account"

    provider = fields.Selection(
        selection_add=[("sms_clicksend", "SMS ClickSend")],
        ondelete={"sms_clicksend": "cascade"},
    )
    sms_clicksend_username = fields.Char(string="API Username")
    sms_clicksend_password = fields.Char(string="API Key")

    @api.onchange('provider')
    def _onchange_provider(self):
        """ClickSend accounts are always for SMS and always registered"""
        if self.provider == 'sms_clicksend':
            self.service_id = self.env['iap.service'].search(
                [('technical_name', '=', 'sms')], limit=1
            )
            self.state = 'registered'

    @api.model_create_multi
    def create(self, vals_list):
        """Always treat ClickSend accounts as registered"""
        for vals in vals_list:
            if vals.get('provider') == 'sms_clicksend':
                vals['state'] = 'registered'
        return super().create(vals_list)

    def write(self, vals):
        """Always treat ClickSend accounts as registered"""
        if vals.get('provider') == 'sms_clicksend':
            vals['state'] = 'registered'
        return super().write(vals)

    def _get_account_info(self, account_id, balance, information):
        """Mock account info query for ClickSend"""
        if self.provider == "sms_clicksend":
            # TODO: Query Clicksend API to get the balance
            return {
                'balance': False,
                'warning_threshold': 0.0,
                'state': 'registered',
                'service_locked': True,
            }
        return super()._get_account_info(account_id, balance, information)

and

<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
    <record id="iap_account_view_form" model="ir.ui.view">
        <field name="model">iap.account</field>
        <field name="inherit_id" ref="iap.iap_account_view_form" />
        <field name="arch" type="xml">
            <xpath expr="//group[@name='account']" position="after">
                <group
                    string="ClickSend account"
                    name="clicksend"
                    invisible="provider != 'sms_clicksend'"
                >
                    <field name="service_id" readonly="1" />
                    <field name="sms_clicksend_username" />
                    <field name="sms_clicksend_password" />
                </group>
            </xpath>
        </field>
    </record>
</odoo>

Would be nice if there was a hook for treating an alternative account as registered. In fact, given the odoo.com-centric treatment of that it could probably just be the default to treat alternative accounts as registered.

dannyadair avatar Jul 11 '25 01:07 dannyadair

/ocabot migration iap_alternative_provider /ocabot merge nobump

dreispt avatar Oct 09 '25 16:10 dreispt

This PR looks fantastic, let's merge it! Prepared branch 18.0-ocabot-merge-pr-3241-by-dreispt-bump-nobump, awaiting test results.

OCA-git-bot avatar Oct 09 '25 16:10 OCA-git-bot

It looks like something changed on 18.0 in the meantime. Let me try again (no action is required from you). Prepared branch 18.0-ocabot-merge-pr-3241-by-dreispt-bump-nobump, awaiting test results.

OCA-git-bot avatar Oct 09 '25 16:10 OCA-git-bot

Congratulations, your PR was merged at c0040d5816c406f047c97076d6cb66c64110bdd0. Thanks a lot for contributing to OCA. ❤️

OCA-git-bot avatar Oct 09 '25 16:10 OCA-git-bot