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
3469 Widoki

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

Awatar
Odrzuć
Najlepsza odpowiedź

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

Awatar
Odrzuć
Autor

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

Autor

thank you @Niyas for the link to guide.

Powiązane posty Odpowiedzi Widoki Czynność
2
maj 23
3188
1
kwi 24
1505
2
lut 24
2140
3
gru 23
5789
1
sie 23
2816