Odoo Help

0

0
1 Risposta
1
Avatar

Odoo Tools Federazione Russa

--Odoo Tools--
10440
| 6 3 9
St Petersburg, Federazione Russa
--Odoo Tools--

OdooTools is the team of developers and business analysts to help you extend Odoo potential. We have been communicating with end users to whom the software became the main business tool since 2012. As a result, we are proud of dozens of successful Odoo apps developed. We are open for new ideas and challenges to create the best Odoo tools for business needs all over the world.

The apps you may like to implement in your Odoo

KnowSystem - the tool to build deep and structured knowledge base for internal and external use

OwnCloud / NextCloud Odoo Integration - the tool to automatically synchronize Odoo attachments with OwnCloud / NextCloud files in both ways

Joint Calendar - the tool to combine different Odoo events in a few configurable calendars

Google Drive Odoo Integration - the tool to automatically synchronize Odoo attachments with Google Drive files in both ways

Product Management Interface - the tool to search, select and update product templates in batch

OneDrive / SharePoint Odoo Integration - the tool to automatically synchronize Odoo attachments with OneDrive files in both ways

Periodic Reporting and Reminders - the tool to generate and periodically send reports and reminders

--> More apps
Odoo Tools Federazione Russa
15/11/18, 10:40

Hi,

it is better to avoid using the standard field parent_id which is of the many2one type. There is logic which relies upon that, and you would spent quite much time to recover it.

It is better to introduce 2 new fields of many2many:

contact_m2m_ids = fields.Many2many(
    "res.partner",
    "rel_table",
    "direct_rel_id",
    "back_rel_id",
    string="Contacts"
)
parents_m2m_ids = fields.Many2many(
    "res.partner",
    "rel_table",
    "back_rel_id",
    "direct_rel_id",   
    string="Companies"
)

Basically, many2many fields are based on a intermediary table, which might be used for both direct and backward relation. In the example it is the table 'rel_table', which has 2 columns 'back_rel_id' & 'direct_rel_id'. It is possible to avoid defining 'rel_table': but if you have 2 relational fields for the same model, it will not work. For more info look at: https://www.odoo.com/documentation/10.0/reference/orm.html#relational-fields

If you want to use 'parent_id' anyway, then it is better to make a computed m2m field, which would use it but would not redefine it:

@api.multi
@api.depends("parent_id")
def _compute_m2m_parents_ids(self):
    for partner in self:
        if partner.parent_id:
            partner.m2m_parents_ids = [(6, 0, [partner.parent_id.id])]
        else:
            partner.m2m_parents_ids = [(6, 0, [])]            
m2m_parents_ids = fields.Many2many(   
"res.partner",   
"rel_table",    
"back_rel_id",    
"direct_rel_id",      
string="Companies",
    compute=_compute_m2m_parents_ids,
    store=True,
)
1 Commento
wizardz Svizzera
26/11/18, 03:00

thank you

Fai una domanda
Writer
Keep Informed
2 follower(s)
About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

Register
Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now