How to filter Many2one value depend another field?












1














please I have a custom module here is a capture :



enter image description here



then I go to Sales order and modify the module sale.order.line i add some fields in relation with my custom module



enter image description here



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



enter image description here



here is my code :



enter image description here



enter image description here










share|improve this question



























    1














    please I have a custom module here is a capture :



    enter image description here



    then I go to Sales order and modify the module sale.order.line i add some fields in relation with my custom module



    enter image description here



    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



    enter image description here



    here is my code :



    enter image description here



    enter image description here










    share|improve this question

























      1












      1








      1







      please I have a custom module here is a capture :



      enter image description here



      then I go to Sales order and modify the module sale.order.line i add some fields in relation with my custom module



      enter image description here



      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



      enter image description here



      here is my code :



      enter image description here



      enter image description here










      share|improve this question













      please I have a custom module here is a capture :



      enter image description here



      then I go to Sales order and modify the module sale.order.line i add some fields in relation with my custom module



      enter image description here



      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



      enter image description here



      here is my code :



      enter image description here



      enter image description here







      odoo odoo-10






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 13 at 21:00









      Mahmoud

      9810




      9810
























          2 Answers
          2






          active

          oldest

          votes


















          1














          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.






          share|improve this answer

















          • 1




            SO helpful thanks a lot friend its work perfect :)
            – Mahmoud
            Nov 14 at 11:25



















          1














          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.






          share|improve this answer





















          • Thank you it works
            – Mahmoud
            Nov 16 at 10:10











          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
          });


          }
          });














          draft saved

          draft discarded


















          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









          1














          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.






          share|improve this answer

















          • 1




            SO helpful thanks a lot friend its work perfect :)
            – Mahmoud
            Nov 14 at 11:25
















          1














          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.






          share|improve this answer

















          • 1




            SO helpful thanks a lot friend its work perfect :)
            – Mahmoud
            Nov 14 at 11:25














          1












          1








          1






          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          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














          • 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













          1














          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.






          share|improve this answer





















          • Thank you it works
            – Mahmoud
            Nov 16 at 10:10
















          1














          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.






          share|improve this answer





















          • Thank you it works
            – Mahmoud
            Nov 16 at 10:10














          1












          1








          1






          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.






          share|improve this answer












          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.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 15 at 6:57









          EasyOdoo

          7,0742723




          7,0742723












          • 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




          Thank you it works
          – Mahmoud
          Nov 16 at 10:10


















          draft saved

          draft discarded




















































          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.




          draft saved


          draft discarded














          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





















































          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







          Popular posts from this blog

          Guess what letter conforming each word

          Port of Spain

          Run scheduled task as local user group (not BUILTIN)