How to filter Many2one value depend another field?
please I have a custom module here is a capture :
then I go to Sales order and modify the module sale.order.line i add some fields in relation with my custom module
Now my request is in ligne contrat i want only lignes in the contrat
for example if i choose Contrat 01 only ligne in Contrat 01 like this
here is my code :
odoo odoo-10
add a comment |
please I have a custom module here is a capture :
then I go to Sales order and modify the module sale.order.line i add some fields in relation with my custom module
Now my request is in ligne contrat i want only lignes in the contrat
for example if i choose Contrat 01 only ligne in Contrat 01 like this
here is my code :
odoo odoo-10
add a comment |
please I have a custom module here is a capture :
then I go to Sales order and modify the module sale.order.line i add some fields in relation with my custom module
Now my request is in ligne contrat i want only lignes in the contrat
for example if i choose Contrat 01 only ligne in Contrat 01 like this
here is my code :
odoo odoo-10
please I have a custom module here is a capture :
then I go to Sales order and modify the module sale.order.line i add some fields in relation with my custom module
Now my request is in ligne contrat i want only lignes in the contrat
for example if i choose Contrat 01 only ligne in Contrat 01 like this
here is my code :
odoo odoo-10
odoo odoo-10
asked Nov 13 at 21:00
Mahmoud
9810
9810
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
You can use a domain in the field definition in your XML:
<field name="contrat_name_id"/>
<field name="contrat_lignes_id" domain="[('ligne_ids', '=', contrat_name_id)]"/>
This will filter contrat_lignes_id to only show records where ligne_ids matches what you entered for contrat_name_id on that line.
1
SO helpful thanks a lot friend its work perfect :)
– Mahmoud
Nov 14 at 11:25
add a comment |
What @djames did will work only in this form view if you want
to have this behavior in all your sale.order.line
views use python
to do this job for you.
class bons_lines(model.Model):
_inherit = 'sale.order.line'
# your new fields
....
....
@api.onchange('contrat_name_id')
def onchange_contrat_name(self):
if self.contrat_name_id:
# add the domain
self.contrat_lignes_id = False # force the user to reselect the contrat_lignes_id if he changes the contrat name
return {'domain': {'contrat_lignes_id': [('ligne_ids', '=', self.contrat_name_id.id)]}}
else:
# remove the domain
return {'domain': {'contrat_lignes_id': }}
This way you will not have to add the domain in every XML view you declare.
Thank you it works
– Mahmoud
Nov 16 at 10:10
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289427%2fhow-to-filter-many2one-value-depend-another-field%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use a domain in the field definition in your XML:
<field name="contrat_name_id"/>
<field name="contrat_lignes_id" domain="[('ligne_ids', '=', contrat_name_id)]"/>
This will filter contrat_lignes_id to only show records where ligne_ids matches what you entered for contrat_name_id on that line.
1
SO helpful thanks a lot friend its work perfect :)
– Mahmoud
Nov 14 at 11:25
add a comment |
You can use a domain in the field definition in your XML:
<field name="contrat_name_id"/>
<field name="contrat_lignes_id" domain="[('ligne_ids', '=', contrat_name_id)]"/>
This will filter contrat_lignes_id to only show records where ligne_ids matches what you entered for contrat_name_id on that line.
1
SO helpful thanks a lot friend its work perfect :)
– Mahmoud
Nov 14 at 11:25
add a comment |
You can use a domain in the field definition in your XML:
<field name="contrat_name_id"/>
<field name="contrat_lignes_id" domain="[('ligne_ids', '=', contrat_name_id)]"/>
This will filter contrat_lignes_id to only show records where ligne_ids matches what you entered for contrat_name_id on that line.
You can use a domain in the field definition in your XML:
<field name="contrat_name_id"/>
<field name="contrat_lignes_id" domain="[('ligne_ids', '=', contrat_name_id)]"/>
This will filter contrat_lignes_id to only show records where ligne_ids matches what you entered for contrat_name_id on that line.
answered Nov 14 at 10:33
djames
642
642
1
SO helpful thanks a lot friend its work perfect :)
– Mahmoud
Nov 14 at 11:25
add a comment |
1
SO helpful thanks a lot friend its work perfect :)
– Mahmoud
Nov 14 at 11:25
1
1
SO helpful thanks a lot friend its work perfect :)
– Mahmoud
Nov 14 at 11:25
SO helpful thanks a lot friend its work perfect :)
– Mahmoud
Nov 14 at 11:25
add a comment |
What @djames did will work only in this form view if you want
to have this behavior in all your sale.order.line
views use python
to do this job for you.
class bons_lines(model.Model):
_inherit = 'sale.order.line'
# your new fields
....
....
@api.onchange('contrat_name_id')
def onchange_contrat_name(self):
if self.contrat_name_id:
# add the domain
self.contrat_lignes_id = False # force the user to reselect the contrat_lignes_id if he changes the contrat name
return {'domain': {'contrat_lignes_id': [('ligne_ids', '=', self.contrat_name_id.id)]}}
else:
# remove the domain
return {'domain': {'contrat_lignes_id': }}
This way you will not have to add the domain in every XML view you declare.
Thank you it works
– Mahmoud
Nov 16 at 10:10
add a comment |
What @djames did will work only in this form view if you want
to have this behavior in all your sale.order.line
views use python
to do this job for you.
class bons_lines(model.Model):
_inherit = 'sale.order.line'
# your new fields
....
....
@api.onchange('contrat_name_id')
def onchange_contrat_name(self):
if self.contrat_name_id:
# add the domain
self.contrat_lignes_id = False # force the user to reselect the contrat_lignes_id if he changes the contrat name
return {'domain': {'contrat_lignes_id': [('ligne_ids', '=', self.contrat_name_id.id)]}}
else:
# remove the domain
return {'domain': {'contrat_lignes_id': }}
This way you will not have to add the domain in every XML view you declare.
Thank you it works
– Mahmoud
Nov 16 at 10:10
add a comment |
What @djames did will work only in this form view if you want
to have this behavior in all your sale.order.line
views use python
to do this job for you.
class bons_lines(model.Model):
_inherit = 'sale.order.line'
# your new fields
....
....
@api.onchange('contrat_name_id')
def onchange_contrat_name(self):
if self.contrat_name_id:
# add the domain
self.contrat_lignes_id = False # force the user to reselect the contrat_lignes_id if he changes the contrat name
return {'domain': {'contrat_lignes_id': [('ligne_ids', '=', self.contrat_name_id.id)]}}
else:
# remove the domain
return {'domain': {'contrat_lignes_id': }}
This way you will not have to add the domain in every XML view you declare.
What @djames did will work only in this form view if you want
to have this behavior in all your sale.order.line
views use python
to do this job for you.
class bons_lines(model.Model):
_inherit = 'sale.order.line'
# your new fields
....
....
@api.onchange('contrat_name_id')
def onchange_contrat_name(self):
if self.contrat_name_id:
# add the domain
self.contrat_lignes_id = False # force the user to reselect the contrat_lignes_id if he changes the contrat name
return {'domain': {'contrat_lignes_id': [('ligne_ids', '=', self.contrat_name_id.id)]}}
else:
# remove the domain
return {'domain': {'contrat_lignes_id': }}
This way you will not have to add the domain in every XML view you declare.
answered Nov 15 at 6:57
EasyOdoo
7,0742723
7,0742723
Thank you it works
– Mahmoud
Nov 16 at 10:10
add a comment |
Thank you it works
– Mahmoud
Nov 16 at 10:10
Thank you it works
– Mahmoud
Nov 16 at 10:10
Thank you it works
– Mahmoud
Nov 16 at 10:10
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53289427%2fhow-to-filter-many2one-value-depend-another-field%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown