Skip to Content
Menu
This question has been flagged
3 Replies
4114 Views

In the sales order model when changing the salesperson field in the other info tab, I need it to change also in the account.move model (In the invoices under the other info tab) to be the same value (same salesperson I chose). Any help or ideas please?

Avatar
Discard
Best Answer

Try this one 

class SaleOrder(models.Model):
_inherit = "sale.order"

@api.onchange('user_id')
def _custom_onchange_user_id(self):
moves = self.env['account.move'].browse(self.invoice_ids.ids)
moves.sudo().write({'invoice_user_id': self.user_id.id})

Avatar
Discard
Author

That worked, thank you so much

If it's working then please don't forgot to mark answer right.

Author

Sure its done

Author

I have one more question, what query can be done in order to update the sales person on sales and automatically be updated on invoice? I am using this on odoo shell: update account_move set invoice_user_id='X'; I am getting an error right now and I am still trying, can you help me please?

Try
update account_move set invoice_user_id="user id here" where id="move id here"

Author

Yes this worked on 1 line level, is there a way to update it on different lines? The function I implemented earlier is 100% correct, but now I need to update old invoices sale person field. So I have 10 invoices with sales person different than the ones in sales order. I need a query that links these two fields together and always put a condition that the sales person field should be compatible in both models. Appreciate your help

Author

I created a server action and upon choosing the invoices I want to update the sales person field to be compatible with the sales person field inside sale.order. This is my code: <?xml version="1.0" encoding="UTF-8"?>

<odoo>

<record model="ir.actions.server" id="action_change_sales_person">
<field name="name">Adjust Sales Person Field</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="account.model_account_move"/>
<field name="binding_model_id" ref="account.model_account_move"/>
<field name="state">code</field>
<field name="binding_view_types">list,form</field>
<field name="code">
for record in records:
if record.invoice_user_id != record.user_id:
record._custom_onchange_user_id()
</field>
</record>
</odoo>

Appreciate your support

Best Answer

You have to override onchange function of 'user_id' named 'onchange_user_id' in sale.order and find linked record of account.move to set same record in salesperson field of invoice(invoice_user_id) from sale order.

Avatar
Discard
Author Best Answer

I am using this function:

from odoo import api,fields,models,_

class SOInherit(models.Model):

_inherit = 'sale.order'

@api.onchange('user_id')
def _onchange_user_id(self):
for rec in self:
if rec.user_id:
rec.invoice_user_id = rec.user_id

but there is a link missing between the user_id and the invoice_user_id, can you help me find it?

Avatar
Discard
Related Posts Replies Views Activity
2
Apr 23
1453
2
May 24
35820
2
Nov 22
1480
1
Feb 22
6687
2
Dec 21
2713