Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
3 Trả lời
5937 Lượt xem

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?

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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})

Ảnh đại diện
Huỷ bỏ
Tác giả

That worked, thank you so much

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

Tác giả

Sure its done

Tác giả

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"

Tác giả

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

Tác giả

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

Câu trả lời hay nhất

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.

Ảnh đại diện
Huỷ bỏ
Tác giả Câu trả lời hay nhất

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?

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 4 23
2752
2
thg 2 25
40430
2
thg 11 22
2832
1
thg 2 22
7851
2
thg 12 21
4113