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

[14.0][FIX] fieldservice_account_analytic: Write correct value for customer_id #1088

Conversation

michelerusti
Copy link

The value for customer_id was written with the wrong value as the order.location_id.customer_id points to a different value than the sale order that generates the fsm_order

Also, it was not written at creation

@OCA-git-bot
Copy link
Contributor

Hi @brian10048, @bodedra, @osimallen,
some modules you are maintaining are being modified, check this out!

@max3903 max3903 added this to the 14.0 milestone May 10, 2023
@max3903 max3903 self-assigned this May 10, 2023
@max3903 max3903 changed the title [14.0][FIX]- fieldservice_accont_analytic - write correct value for customer_id [14.0][FIX] fieldservice_account_analytic: write correct value for customer_id May 10, 2023
@max3903 max3903 changed the title [14.0][FIX] fieldservice_account_analytic: write correct value for customer_id [14.0][FIX] fieldservice_account_analytic: Write correct value for customer_id May 10, 2023
@michelerusti michelerusti force-pushed the 14.0-fix-fieldservice_accont_analytic branch from 309ccce to bd25842 Compare May 11, 2023 16:19
@max3903
Copy link
Sponsor Member

max3903 commented May 11, 2023

@michelerusti If you could set those fields in vals before calling super(), they would be set as part of the same transactions.

@michelerusti michelerusti force-pushed the 14.0-fix-fieldservice_accont_analytic branch 4 times, most recently from 2594b3b to d5877ae Compare May 16, 2023 10:03
@michelerusti
Copy link
Author

@michelerusti If you could set those fields in vals before calling super(), they would be set as part of the same transactions.

Yes, thanks for the advise
I've also removed the error assertion in test_fsm_stock_account.py because with this fix the user is set correctly

Let me know if there's anything else needed to do!

Comment on lines 59 to 61
res = super(FSMOrder, self).write(vals)
for order in self:
if "customer_id" not in vals and order.customer_id is False:
order.customer_id = order.location_id.customer_id.id
if "customer_id" not in vals and not order.customer_id:
order.customer_id = order.location_id.customer_id
Copy link
Sponsor Member

@max3903 max3903 May 16, 2023

Choose a reason for hiding this comment

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

@michelerusti I meant something like this:

    def write(self, vals):
        if "customer_id" not in vals and not self.customer_id:
            vals.update({"customer_id": self.location_id.customer_id.id})
        res = super().write(vals)

Copy link
Author

Choose a reason for hiding this comment

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

@max3903 I've edited, me know if it's alright!

@michelerusti michelerusti force-pushed the 14.0-fix-fieldservice_accont_analytic branch 2 times, most recently from 8438b5a to 905b7e1 Compare May 17, 2023 09:55
for order in self:
if "customer_id" not in vals and not order.customer_id:
order.customer_id = order.sale_id.partner_id
return res
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

@michelerusti Same idea for this method

res = super(FSMOrder, self).create(vals)
for order in res:
order.customer_id = order.sale_id.partner_id
return res
Copy link
Sponsor Member

Choose a reason for hiding this comment

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

@michelerusti Same idea but it's a bit different: you need to search the sale order with vals.get("sale_id") to get partner_id first. 1 select and 1 insert is still better than 1 insert and 1 update.

@michelerusti michelerusti force-pushed the 14.0-fix-fieldservice_accont_analytic branch from 905b7e1 to 58f3cc9 Compare May 18, 2023 14:36
…id and the actual customer when sale_id is present
@michelerusti michelerusti force-pushed the 14.0-fix-fieldservice_accont_analytic branch from 58f3cc9 to 89ec76d Compare May 18, 2023 14:38

def write(self, vals):
for order in self:
if "customer_id" not in vals and not order.customer_id:
Copy link
Contributor

Choose a reason for hiding this comment

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

[fsm.order]customer_id is not in the dependencies.

Copy link
Author

Choose a reason for hiding this comment

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

I see...
Since the field is defined in fieldservice_accont_analytic, how would you consider the idea to add that module as a dependency?
Otherwise all this PR would loose meaning

Let me know if there is any different approach you would've preferred

Copy link
Contributor

Choose a reason for hiding this comment

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

There is different approach here. The most two obvious are:

  • you use fieldservice_sale then you may want to invoice based on the sale order (and use analytics from sale order lines)
  • you use create orders directly so you don't have a sale, thanks to fieldservice_account_analytic, you invoice the fsm orders directly.

Do you use another approach ?

From a technical perspective, you can put your code in a new module like fieldservice_sale_analytic.

Copy link
Author

Choose a reason for hiding this comment

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

We create the sale order and let the fsm order be generated by fieldservice_sale .
The problem is the customer_id that results empty when it should be the same customer of the sale order

This means that customer_id should always be available to fieldervice_sale since otherwise it breaks the module and the options are re-difining customer_id or add the dependency of fieldservice_sale_analytic .

I see this as a bug since otherwise the customer_id is not automatically set.
Let me know your thoughts about it and how you think is best to proceed, or even if it's to be considered a bug at all!

Copy link
Author

Choose a reason for hiding this comment

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

From a technical perspective, you can put your code in a new module like fieldservice_sale_analytic.

do you think that for this approach it needs to be created a new module?

Copy link
Contributor

@hparfr hparfr Sep 20, 2023

Choose a reason for hiding this comment

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

If you use sale to generate the fsm order, you do not need customer_id. The order will be invoiced directly by the sale.

Why using fieldservice_analytic ?

Copy link
Author

Choose a reason for hiding this comment

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

If you use sale to generate the fsm order, you do not need customer_id.

@hparfr
And is this definitive or is it open to discussion? It may not be essential but I think that having the correct customer reference would be nice

return super(FSMOrder, self).write(vals)

def create(self, vals):
sale_id = self.env["sale.order"].browse(vals.get("sale_id"))
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

Inherited... how?
Looking in the code, the method _prepare_fsm_values() is not called by the create() but from other methods like this one

@michelerusti michelerusti force-pushed the 14.0-fix-fieldservice_accont_analytic branch from 4d17622 to d97b09d Compare December 13, 2023 15:35
@michelerusti michelerusti force-pushed the 14.0-fix-fieldservice_accont_analytic branch from eaec530 to d121264 Compare December 13, 2023 16:03
Copy link

There hasn't been any activity on this pull request in the past 4 months, so it has been marked as stale and it will be closed automatically if no further activity occurs in the next 30 days.
If you want this PR to never become stale, please ask a PSC member to apply the "no stale" label.

@github-actions github-actions bot added the stale PR/Issue without recent activity, it'll be soon closed automatically. label Apr 14, 2024
@github-actions github-actions bot closed this May 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs fixing stale PR/Issue without recent activity, it'll be soon closed automatically.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants