Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FIX acc_fisc_classif: find or create a classif if none #435

Closed
wants to merge 7 commits into from

Conversation

bealdav
Copy link
Member

@bealdav bealdav commented Jun 11, 2024

  • test

This PR is needed to install all modules of the branch

cc @gurneyalex @yankinmax

@OCA-git-bot
Copy link
Contributor

Hi @legalsylvain,
some modules you are maintaining are being modified, check this out!

@bealdav bealdav marked this pull request as ready for review June 12, 2024 14:02
@bealdav bealdav changed the title FIX acc_fisc_classif: find or create a classif if any FIX acc_fisc_classif: find or create a classif if none Jun 12, 2024
Copy link
Contributor

@legalsylvain legalsylvain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @bealdav. thanks a lot for fixing that point !

  • just a point to fix, the case where there is no taxes and no classification in vals in create mode.
  • otherwise, some minor remarks inline.

@bealdav
Copy link
Member Author

bealdav commented Jun 12, 2024

Thanks a lot @legalsylvain for your review, less code, more test

Copy link
Contributor

@legalsylvain legalsylvain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @bealdav.

regarding create_mode, it was not exactly what I mean. I made a PR that include the changes. See commit messages and feel free to contact me if you have any doubt.

could you take a look and merge it ?

akretion#4

once done, the algorithm has to be fixed ! _find_or_create_classification doesn't return the correct classification. But this is a huge part.

See in a shell on demo data :

>>> bob = self.env["product.template"].create({"name": "TEST", "taxes_id": [], "supplier_taxes_id": []})
>>> bob.fiscal_classification_id.sale_tax_ids
account.tax(2,)
>>> bob.fiscal_classification_id.purchase_tax_ids
account.tax(1,)

Copy link

@mourad-ehm mourad-ehm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@legalsylvain
Copy link
Contributor

@mourad-ehm : what do you think about the bug described here ? #435 (review)

@mourad-ehm
Copy link

I discussed with @bealdav about this bug. He will fix it.

bealdav and others added 2 commits June 13, 2024 11:28
* [FIX] account_product_fiscal_classification : In a context of product creation, if classification is not provided (in import context for exemple), _find_or_create_classification should be allways called to ensure all templates have a classification

* [FIX] account_product_fiscal_classification : if a code make a write vals={supplier_taxes_id: []} this should raise the call of _find_or_create_classification

* [FIX] account_product_fiscal_classification/tests : assertNotEquals is deprecated

* [FIX] account_product_fiscal_classification : explicit supplier and customer taxes in test, to avoid bug if default taxes are defined
Copy link
Contributor

@legalsylvain legalsylvain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like the current algorithm create new fiscal classification each time. Don't you think ?


2024-06-13 22:20:46,653 166314 INFO account_product_fiscal_classification_16_imp odoo.addons.account_product_fiscal_classification.models.product_template: Creating new Fiscal Classification 'Purchase Taxes: Demo Purchase Tax 7% (Company 2) + Demo Purchase Tax 30% (Company 2) - No Sale Taxes' for False 
'Purchase Taxes: Demo Purchase Tax 7% (Company 2) + Demo Purchase Tax 30% (Company 2) - No Sale Taxes'
>>> self.env["product.template"].create({"name": "TEST Coincoin", "supplier_taxes_id": [4, 5]}).fiscal_classification_id.name
2024-06-13 22:20:50,997 166314 INFO account_product_fiscal_classification_16_imp odoo.addons.account_product_fiscal_classification.models.product_template: Creating new Fiscal Classification 'Purchase Taxes: Demo Purchase Tax 7% (Company 2) + Demo Purchase Tax 30% (Company 2) - No Sale Taxes' for False 
'Purchase Taxes: Demo Purchase Tax 7% (Company 2) + Demo Purchase Tax 30% (Company 2) - No Sale Taxes'
>>> self.env["product.template"].create({"name": "TEST Coincoin", "supplier_taxes_id": [4, 5]}).fiscal_classification_id.name

@bealdav
Copy link
Member Author

bealdav commented Jun 14, 2024

You're right !

# this code fails to find classification
>>> env["account.product.fiscal.classification"].search([('sale_tax_ids', 'in', []), ('purchase_tax_ids', 'in', [])])
account.product.fiscal.classification()
# this code achieve to find classifications
>>> env["account.product.fiscal.classification"].search([('sale_tax_ids', '=', False), ('purchase_tax_ids', '=', False)])
account.product.fiscal.classification(5, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44)
# syntax in incorrect
>>> env["account.product.fiscal.classification"].search([('sale_tax_ids', '=', []), ('purchase_tax_ids', '=', [])])
2024-06-14 10:12:07,924 337 WARNING db3 odoo.osv.expression: The domain term '('sale_tax_ids', '=', [])' should use the 'in' or 'not in' operator. 
2024-06-14 10:12:07,924 337 WARNING db3 odoo.osv.expression: The domain term '('purchase_tax_ids', '=', [])' should use the 'in' or 'not in' operator. 

Then the code to define domain should be

        domain = [("sale_tax_ids", "=", False)]
        if sale_tax_ids:
            domain = [("sale_tax_ids", "in", sale_tax_ids)]
        if purchase_tax_ids:
            domain.append(("purchase_tax_ids", "in", purchase_tax_ids))
        else:
            domain.append(("purchase_tax_ids", "=", False))

Are you ok ? @legalsylvain

I have done some additional tests in last commit to secure this kind of failures

@legalsylvain
Copy link
Contributor

I don't think that line works :

domain = [("sale_tax_ids", "in", sale_tax_ids)]

In mean, if sale_tax_ids = [2] and sale_tax_ids = [2, 3] the domain is respected, but we should not select this classification. Don't you think ?

@bealdav
Copy link
Member Author

bealdav commented Jun 14, 2024

Finalement je vois pas d'autres solution qui marche a 100%

        domain = [("sale_tax_ids", "=", False)]
        if sale_tax_ids:
            domain = [("sale_tax_ids", "=", sale_tax_ids)]
        if purchase_tax_ids:
            domain.append(("purchase_tax_ids", "=", purchase_tax_ids))
        else:
            domain.append(("purchase_tax_ids", "=", False))

On pourras rendre cela plus joli tard, mais si cela marche comme ça on pourrais merger ?

Copy link
Contributor

@legalsylvain legalsylvain left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As said privatly the algorithm to guess classification, based on taxes is wrong.

See tests : akretion#6

Thanks for your work, @bealdav !

@legalsylvain
Copy link
Contributor

supersed by #441

@legalsylvain
Copy link
Contributor

Hi @bealdav and @mourad-ehm. I fixed this PR, in #441, but I need review. Could you take a time to review it ?

thanks a lot.

@bealdav bealdav closed this Jul 4, 2024
@bealdav bealdav deleted the find-classif branch July 4, 2024 06:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants