account-analytic icon indicating copy to clipboard operation
account-analytic copied to clipboard

[18.0][MIG] product_analytic : migration to 18.0

Open timloic opened this issue 8 months ago • 7 comments

timloic avatar Apr 17 '25 18:04 timloic

Hey. I found out that there is a small issue in _inverse_product_id method.

Steps how to find it:

  1. Create an Invoice;
  2. Select a product on Invoice Lines that has default analytic account(it should be added automatically when product is selected.)
  3. After product is added, select more Analytic Accounts on analytic_distribution field.
  4. Then press save.

You'll see that only default Analytic Account is added. Any other Analytic Accounts that has been added is deleted from line.

I found out simple fix for now, maybe there is a better solution, but i'll just post it here, you could use it:

    @api.onchange("product_id")
    def _inverse_product_id(self):
        res = super()._inverse_product_id()
        # Compatibility with `pos_analytic_by_config`
        if self.env.context.get("pos_config_id"):
            return res
        for line in self:
            inv_type = line.move_id.move_type
            if line.product_id and inv_type and inv_type != "entry" and not line.analytic_distribution:
                ana_accounts = (
                    line.product_id.product_tmpl_id._get_product_analytic_accounts()
                )
                ana_account = ana_accounts[INV_TYPE_MAP[inv_type]]
                line.analytic_distribution = (
                    {ana_account.id: 100} if ana_account else False
                )
        return res

I just added and not line.analytic_distribution: to if statement. And it seems to work like expected.

Maybe, test for this case should also be added. Thanks.

Mantux11 avatar Apr 25 '25 05:04 Mantux11

@luisDIXMIT , @dreispt, @Mantux11 can you review it again :pray: ? It's fixed.

timloic avatar Jun 11 '25 13:06 timloic

@timloic Thanks, it would have been better to amend your migration commit. Can you squash it plese. Also, can you look at the tests failing?

dreispt avatar Jun 14 '25 13:06 dreispt

@timloic , can you please make the last few changes?

ByteMeAsap avatar Jul 14 '25 15:07 ByteMeAsap

Hi @timloic ,

Thanks for this proposal. Is there any chance to rebase to trigger CI/CD ?

Regards

flotho avatar Aug 25 '25 13:08 flotho

@timloic Sorry for late reply. I just can't find what was changed to fix _inverse_product_id. Maybe I'm blind or something :D

Mantux11 avatar Sep 08 '25 07:09 Mantux11

@timloic Hi, I think this module should be change widget to analytic account with standard odoo. What do you think? https://github.com/OCA/account-analytic/pull/838

Saran440 avatar Oct 02 '25 10:10 Saran440