Skip to Content
Menu
This question has been flagged
1 Reply
3753 Views

I have the following situation: 

An object A has a view with a field many2one of the object B, and B has a many2one of the object C.

A also has a related field A1 which displays a field (C1) in the object C, but we can select its value directly in A view.

I can select an existing B or create a new one. The same with C.

When I select to create new B and C I get the form view for the new object C

 

How can I set the value in C1 to be equal to A1?

 

I'm trying with:

def default_get(self, cr, uid, fields, context=None):
            _logger.info('Inside bdd_project.default_get')
            if context is None:
                context = {}
            res = super(bdd_project, self).default_get(cr, uid, fields, context=context)
            pl_obj = self.pool.get('bdd.pricelist')
            pl = pl_obj.browse(cr, uid, context.get('cus_id'), context=context)
            if 'cus_id' in fields:
                _logger.info('Inside if cus_id: value %s', pl.cus_id)
                res.update({'cus_id': pl.cus_id})
            return res

 

where bdd_project would represent the object C and bdd_pricelist would be A.

pl.cus_id is returning None.

Avatar
Discard
Best Answer

Pau, the notion of having a related field means that you SHOULD NOT edit the value directly.  If you want to sync C1 with the value of A1 which is selected by User, then you should not define A1 as a related field, but define it as a normal field.

Then you on write (or create) of A, you can update the related C1 field value based on the value set by user.

Avatar
Discard
Author

The normal flow should be from C to A, I mean that C1 should be already defined when the view A is opened, and that's why it's a related field. But there's a rare scenario where an user could want start defining from A to C, and that's why I need to implement it this way.

Pau, even if it is a rare chance, you still need to implement the synchronization, i.e. change A1 if C1 is updated and C1 if A1 is updated. You still can default A1 to display whatever value C1 is holding. Another approach that you may want to consider is to display B in A's form and C in B's form, hence user can change C1 from C's form instead of changing it from A's form. More longwinded for user, I understand.

Author

John, what do you mean by implement the synchronization? Do you have a link to any document explaining how to do it? The request is to display C1 in A, and then filter B by this value.

Pau, your first problem description is that user need to be able to change A1 and then C1 need to be change to be equal to A1. Does this still a requirement? If so, my answer stands. Synchronization is basically changing C1 when A1 is changed by user and A1 if C1 is selected by user. You need to inherit method write of both class A and C. For, say class A, you need to detect if there is any change in A1, and then change the related C1 value to be the same as A1, vv. If your first problem description is not correct, then I would suggest that you restate what you really need so the answer can be crafted more accurately.

Related Posts Replies Views Activity
2
Mar 15
7868
2
Mar 15
3643
0
Mar 15
3485
0
Mar 15
4022
1
Jun 16
3906