Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
3397 Visualizzazioni

is it possible? is it correct way for Man2one field? 


i have following models:

1) coa_ledgers with id, acc_name, ledger_acc etc.
2) banks with id, bank_name, ledger_acc etc.


for my banks field 'ledger_acc' is Many2one to select from coa_ledgers and it should return the value of 'ledger_acc' field instead of 'id' field means in banks Many2one field will display 'acc_name' field and should return 'ledger_acc' field value and NOT return 'id' field value )

how i can achieve this? please help.

in my Model for banks i have Many2one field as below (by default this will Return 'id' field value from coa_ledgers to Many2one field to store the value but i want it to Return 'ledger_acc' field to store the value)

ledger_acc = fields.Many2one('coa_ledgers', string='Ledger A/c')

kindly help with all possible way(s).

regards

Avatar
Abbandona
Risposta migliore

Hi,

When you save a many2one field, it will always save the field value to the database its ID. 

In user interface if you need to change the value displayed in the selection, either you can achieve it by adding _rec_name or by defining name_get function for the model.

As it is a many2one field and if you have a recordset of the current model, you can access anyway values inside the m20 model using the . operator, eg: self.field_name.ledger_acc


* Rec name in Odoo

* Odoo Name Get Function

* Odoo ORM


Thanks

Avatar
Abbandona
Autore

thank you @Niyas for help. the . operator method sounds great for this purpose when we have no any other way to do this as i have asked.
will check this and confirm.
please, any link of your video guides for custom app/module how to inherit and use fields from invoice, sales, purchase etc. ( because these are have transaction level data which have deep impact in odoo system ), if there is any, please give link(s) to learn for customization with proper data handling.
regards
regards

Autore

thank you @Niyas for the link to guide.

Post correlati Risposte Visualizzazioni Attività
2
mag 23
3129
1
apr 24
1454
2
feb 24
2059
3
dic 23
5671
1
ago 23
2755