Skip to Content
Menu
Dette spørgsmål er blevet anmeldt
1 Svar
3380 Visninger

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
Kassér
Bedste svar

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
Kassér
Forfatter

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

Forfatter

thank you @Niyas for the link to guide.

Related Posts Besvarelser Visninger Aktivitet
2
maj 23
3113
1
apr. 24
1432
2
feb. 24
2045
3
dec. 23
5644
1
aug. 23
2742