Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
2430 Widoki

I created a function that does the following job: when changing the sales person field inside sale.order model under 'other info' tab, it will automatically change the sales person field inside the invoices (account.move) in the 'other info' tab also. Here is my function:


class SaleOrder(models.Model):
_inherit = "account.move"

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

The first step is done, but the 2nd step is that I have about 100 invoices that have a salesperson different than the one found in the sales order and I want to change them fastly. So, I created a server action and upon selecting them all I will change the sales person field to the same one found inside the sales order. Here is the code:




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





Now pressing on the action button I am getting an error, can anyone help me adjust this code? Thanks

Awatar
Odrzuć

please update the question with error message

Najlepsza odpowiedź
 for record in self:
record._custom_onchange_user_id()

You have to make loop on self

Because you will get records in self:

records doesn't contain anything

Awatar
Odrzuć
Powiązane posty Odpowiedzi Widoki Czynność
0
mar 22
3465
0
lis 21
4371
0
sie 21
2447
2
paź 15
4864
1
lip 24
1653