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
[14.0][FIX] fieldservice_account_analytic: Write correct value for customer_id #1088
Conversation
Hi @brian10048, @bodedra, @osimallen, |
309ccce
to
bd25842
Compare
@michelerusti If you could set those fields in vals before calling super(), they would be set as part of the same transactions. |
2594b3b
to
d5877ae
Compare
Yes, thanks for the advise Let me know if there's anything else needed to do! |
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 |
There was a problem hiding this comment.
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)
There was a problem hiding this comment.
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!
8438b5a
to
905b7e1
Compare
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
905b7e1
to
58f3cc9
Compare
…id and the actual customer when sale_id is present
58f3cc9
to
89ec76d
Compare
|
||
def write(self, vals): | ||
for order in self: | ||
if "customer_id" not in vals and not order.customer_id: |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be inherit from here : https://github.com/OCA/field-service/blob/14.0/fieldservice_sale/models/sale_order.py#L67
There was a problem hiding this comment.
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
…nalytic Add missing @api.model decorator to FSMOrder.create() override
4d17622
to
d97b09d
Compare
eaec530
to
d121264
Compare
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. |
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_orderAlso, it was not written at creation