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

[16.0][FIX] sale_invoice_policy: re-structure module so that there is no need to change the original invoice_policy field #2763

Closed

Conversation

ACheung-FactorLibre
Copy link
Contributor

FIX for: #2725

@rousseldenis
Copy link
Sponsor Contributor

@ACheung-FactorLibre The fix should not be as this simple as the code depends on the context which is not suitable for stored values.

@ACheung-FactorLibre
Copy link
Contributor Author

Yes @rousseldenis, you're right.

@ACheung-FactorLibre
Copy link
Contributor Author

ACheung-FactorLibre commented Nov 7, 2023

Hi @rousseldenis, I think modifying the fields on the model product.template is not necessary. You can calculate the qty_to_invoice per line without modifying the fields.

Here is a suggestion for _compute_qty_to_invoice():

    @api.depends(
        "qty_invoiced",
        "qty_delivered",
        "product_uom_qty",
        "state",
        "order_id.invoice_policy",
    )
    def _compute_qty_to_invoice(self):
        if not self.order_id.invoice_policy:
            return super()._compute_qty_to_invoice()
        if self.order_id.invoice_policy == 'order':
            for line in self:
                line.qty_to_invoice = line.product_uom_qty - line.qty_invoiced
        else:
            for line in self:
                line.qty_to_invoice = line.qty_delivered - line.qty_invoiced
        return True

PD: Are you working on the FIX? If you are not, I'll commit my changes on this PR, otherwise, this is just a suggestion and I'll let you FIX it.

@rousseldenis
Copy link
Sponsor Contributor

Hi @rousseldenis, I think modifying the fields on the model product.template is not necessary. You can calculate the qty_to_invoice per line without modifying the fields.

Here is a suggestion for _compute_qty_to_invoice():

    @api.depends(
        "qty_invoiced",
        "qty_delivered",
        "product_uom_qty",
        "state",
        "order_id.invoice_policy",
    )
    def _compute_qty_to_invoice(self):
        if not self.order_id.invoice_policy:
            return super()._compute_qty_to_invoice()
        if self.order_id.invoice_policy == 'order':
            for line in self:
                line.qty_to_invoice = line.product_uom_qty - line.qty_invoiced
        else:
            for line in self:
                line.qty_to_invoice = line.qty_delivered - line.qty_invoiced
        return True

PD: Are you working on the FIX? If you are not, I'll commit my changes on this PR, otherwise, this is just a suggestion and I'll let you FIX it.

Nope, not so much time for that. Wanted to fix the main branch as priority. You can go on with your proposal

@ACheung-FactorLibre ACheung-FactorLibre force-pushed the 16.0-fix-sale_invoice_policy branch 3 times, most recently from 76ad6cd to de989ad Compare November 10, 2023 12:06
@ACheung-FactorLibre ACheung-FactorLibre marked this pull request as ready for review November 10, 2023 12:12
@ACheung-FactorLibre ACheung-FactorLibre changed the title [16.0][FIX] sale_invoice_policy: store=True on invoice_policy field [16.0][FIX] sale_invoice_policy: re-structure module so that there is no need to change the original invoice_policy field Nov 10, 2023
@ACheung-FactorLibre ACheung-FactorLibre force-pushed the 16.0-fix-sale_invoice_policy branch 2 times, most recently from c047218 to 66ebadd Compare November 13, 2023 11:19
@hugo-cordoba hugo-cordoba force-pushed the 16.0-fix-sale_invoice_policy branch 2 times, most recently from 5f0a8fe to 66ebadd Compare November 22, 2023 13:09
@ACheung-FactorLibre
Copy link
Contributor Author

Hello @rousseldenis @pedrobaeza,

Could you review this?

Thank you

@pedrobaeza pedrobaeza added this to the 16.0 milestone Dec 14, 2023
If the product is type = 'service', we don't have to apply the invoice
policy given by the context.
:return:
"""
invoice_policy = self.env.context.get("invoice_policy")
Copy link
Member

Choose a reason for hiding this comment

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

Don't remove the depends_context if still used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Pedro,
depends_context is used to return a decorator that specifies the context dependencies of a non-stored "compute" method. Since the field is stored on the database, it will not run the method even if invoice_policy is changed by context.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, but you are still using a context value, so both are incompatible. You can't depend on a context if it's stored.


@api.depends("detailed_type", "default_invoice_policy")
@api.depends_context("invoice_policy")
@api.depends("detailed_type")
def _compute_invoice_policy(self):
Copy link
Member

Choose a reason for hiding this comment

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

Why still this method if the field is not computed? And IMO, this should be adjusted on the sales order fields, not here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi Pedro,

Yes, the field is computed, here is Odoo's declaration of the field:

    invoice_policy = fields.Selection(
        [('order', 'Ordered quantities'),
         ('delivery', 'Delivered quantities')], string='Invoicing Policy',
        compute='_compute_invoice_policy', store=True, readonly=False, precompute=True,
        help='Ordered Quantity: Invoice quantities ordered by the customer.\n'
             'Delivered Quantity: Invoice quantities delivered to the customer.')

@rafaelbn
Copy link
Member

rafaelbn commented Mar 9, 2024

Hello @ACheung-FactorLibre ,

thank you for this PR and this effors. Just to have the situation:

In your opinion, which is the state of this PR and what would you like to happend with it?

I kindly ask just to figure out how to help 😄 ❤️

Thanks in advance
Best regards

@ACheung-FactorLibre
Copy link
Contributor Author

Hello @rafaelbn,

Well, in my opinion, this PR is ready, but there are some changes that have been requested that have not been applied yet.
If anyone wants to open a PR with those changes, it would be great.

Thank you @rafaelbn
Best regards

@ACheung-FactorLibre
Copy link
Contributor Author

Hi @pedrobaeza,

Changes have been applied, could you please review them?

Thank you for your time

@pedrobaeza
Copy link
Member

There are still some red tests.

@ACheung-FactorLibre
Copy link
Contributor Author

There are still some red tests.

Hello @pedrobaeza, corrected.

Thank you

Copy link
Member

@pedrobaeza pedrobaeza left a comment

Choose a reason for hiding this comment

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

There's a merge commit that shouldn't be there. You should rebase. And the technique used writing on the product is a very weak one. What you should do is to intercept the to invoice quantity compute methods to take into account the invoice policy.

…ed to change the original invoice_policy field
@ACheung-FactorLibre
Copy link
Contributor Author

Hi @pedrobaeza,
Could you please explain this?

And the technique used writing on the product is a very weak one. What you should do is to intercept the to invoice quantity compute methods to take into account the invoice policy.

Thank you

@pedrobaeza
Copy link
Member

pedrobaeza commented Apr 22, 2024

Override the compute method for the quantity to invoice and put that quantity according the invoice policy set in the order.

@pedrobaeza
Copy link
Member

Supersede by #3102

@pedrobaeza pedrobaeza closed this Apr 25, 2024
@ACheung-FactorLibre ACheung-FactorLibre deleted the 16.0-fix-sale_invoice_policy branch May 6, 2024 07:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants