Skip to Content
मेन्यू
This question has been flagged
3 Replies
4602 Views

Hello masters, am new to odoo i need you assistance for below issue. any help would be appreciated.  

I need to create a many2one relation between account.move and account.payment. In odoo15 web i can choose only model, not field of co-model while creating. Is there any way to choose the field in ui. 

scenario is i need to add the date from payments model to invoice tree view.

Note i did not use ssh version its odoo 15 online version.

Thanks in advance.

Avatar
Discard
Best Answer

When you define a Many2one field in Odoo, you specify the model (comodel) that the field is related to. However, you don’t directly choose a specific field in the comodel. Instead, the Many2one field stores the ID of the related record in the comodel.

For example, if you have a Many2one field in the account.move model that relates to the account.payment model, this field would store the ID of a specific account.payment record. When you view an account.move record in the Odoo UI, this Many2one field would display the name field of the related account.payment record.


If you want to display a different field from the account.payment model in the UI, you would need to add a related field to the account.move model. A related field in Odoo is a read-only field that uses the values from another field. You could add a related field to account.move that uses the value of the field you want to display from the account.payment model.


Here’s an example of how you might define a Many2one field and a related field in the account.move model:


class AccountMove(models.Model):

    _inherit = 'account.move'


    payment_id = fields.Many2one('account.payment', string='Payment')

    payment_field = fields.Char(related='payment_id.field', string='Payment Field')


In this example, payment_id is a Many2one field that relates to the account.payment model. payment_field is a related field that uses the value of the field field from the account.payment model. Replace 'field' with the name of the field you want to display.

Please note that while you can add these fields in the Odoo UI, you might find it easier to add them in the Python code. If you’re using Odoo Online, you would need to use Odoo Studio to add these fields in the UI.

Best regards,
Maciej Burzymowski

Avatar
Discard
Best Answer

Hi,

By default, fields created in Odoo Studio are not visible on website forms. This is because, upon creation, these Studio fields are blacklisted for website use. To make them available for selection on the website, you need to unblacklist them. To do this, ensure you're in developer mode, then navigate to Settings -> Technical -> Fields. Search for the field you want to display on the website and deselect the 'Blacklisted' checkbox. Once saved, the field can be used on the website. Alternatively, you can directly manage this setting from Studio by clicking the 'More' button in the field properties.


Hope it helps

Avatar
Discard
Author Best Answer

Hi Maciej Burzymowski,

Thanks for your prompt response, much appreciate it.

I have tried what you told like, i have created one field that have relation of many2one. Using that field i tried to access other fields like this x.date in the co-model but its did not help me. I didn't get any value. 

Thank you so much for your reply.

Avatar
Discard
Related Posts Replies Views Activity
1
अक्तू॰ 24
1715
2
अक्तू॰ 24
3064
1
जुल॰ 24
2317
0
जून 24
1188
2
फ़र॰ 24
2755