Call funtion when Odoo record created












1















Actually,I want to send message to topic with use of google cloud pubsub when any record created/updated at Odoo server



I override create function as below



@api.model
def create(self, values):
values = self._remove_reified_groups(values)
user = super(Users, self).create(values) // created and return id just like res.users(67,)
group_multi_company = self.env.ref('base.group_multi_company', False)
if group_multi_company and 'company_ids' in values:
if len(user.company_ids) <= 1 and user.id in group_multi_company.users.ids:
group_multi_company.write({'users': [(3, user.id)]})
elif len(user.company_ids) > 1 and user.id not in group_multi_company.users.ids:
group_multi_company.write({'users': [(4, user.id)]})

# Publish message to subscriber
pubsub = PubSub()

// Here I used own middleware service which is used for CRUD opertion on
Odoo model
// Below API return record of model 'res.users'
// Here user.id return 67
req = requests.get('http://localhost:8080/users/' + str(user.id))
fetch_user = req.text // response return user not found because record nor save in table
result = pubsub.publish_message_on_topic(self.project_id, self.topic_name, fetch_user)
return user


In create function user created & its return id in user variable but its not save in table until 'return user'(last line of function) not run. I don't know how create functionality worked in Odoo?



So,I search on any event triggered when record created/updated so I will implement my pubsub logic to that function.



Any help or suggestion?



Thank you.










share|improve this question



























    1















    Actually,I want to send message to topic with use of google cloud pubsub when any record created/updated at Odoo server



    I override create function as below



    @api.model
    def create(self, values):
    values = self._remove_reified_groups(values)
    user = super(Users, self).create(values) // created and return id just like res.users(67,)
    group_multi_company = self.env.ref('base.group_multi_company', False)
    if group_multi_company and 'company_ids' in values:
    if len(user.company_ids) <= 1 and user.id in group_multi_company.users.ids:
    group_multi_company.write({'users': [(3, user.id)]})
    elif len(user.company_ids) > 1 and user.id not in group_multi_company.users.ids:
    group_multi_company.write({'users': [(4, user.id)]})

    # Publish message to subscriber
    pubsub = PubSub()

    // Here I used own middleware service which is used for CRUD opertion on
    Odoo model
    // Below API return record of model 'res.users'
    // Here user.id return 67
    req = requests.get('http://localhost:8080/users/' + str(user.id))
    fetch_user = req.text // response return user not found because record nor save in table
    result = pubsub.publish_message_on_topic(self.project_id, self.topic_name, fetch_user)
    return user


    In create function user created & its return id in user variable but its not save in table until 'return user'(last line of function) not run. I don't know how create functionality worked in Odoo?



    So,I search on any event triggered when record created/updated so I will implement my pubsub logic to that function.



    Any help or suggestion?



    Thank you.










    share|improve this question

























      1












      1








      1








      Actually,I want to send message to topic with use of google cloud pubsub when any record created/updated at Odoo server



      I override create function as below



      @api.model
      def create(self, values):
      values = self._remove_reified_groups(values)
      user = super(Users, self).create(values) // created and return id just like res.users(67,)
      group_multi_company = self.env.ref('base.group_multi_company', False)
      if group_multi_company and 'company_ids' in values:
      if len(user.company_ids) <= 1 and user.id in group_multi_company.users.ids:
      group_multi_company.write({'users': [(3, user.id)]})
      elif len(user.company_ids) > 1 and user.id not in group_multi_company.users.ids:
      group_multi_company.write({'users': [(4, user.id)]})

      # Publish message to subscriber
      pubsub = PubSub()

      // Here I used own middleware service which is used for CRUD opertion on
      Odoo model
      // Below API return record of model 'res.users'
      // Here user.id return 67
      req = requests.get('http://localhost:8080/users/' + str(user.id))
      fetch_user = req.text // response return user not found because record nor save in table
      result = pubsub.publish_message_on_topic(self.project_id, self.topic_name, fetch_user)
      return user


      In create function user created & its return id in user variable but its not save in table until 'return user'(last line of function) not run. I don't know how create functionality worked in Odoo?



      So,I search on any event triggered when record created/updated so I will implement my pubsub logic to that function.



      Any help or suggestion?



      Thank you.










      share|improve this question














      Actually,I want to send message to topic with use of google cloud pubsub when any record created/updated at Odoo server



      I override create function as below



      @api.model
      def create(self, values):
      values = self._remove_reified_groups(values)
      user = super(Users, self).create(values) // created and return id just like res.users(67,)
      group_multi_company = self.env.ref('base.group_multi_company', False)
      if group_multi_company and 'company_ids' in values:
      if len(user.company_ids) <= 1 and user.id in group_multi_company.users.ids:
      group_multi_company.write({'users': [(3, user.id)]})
      elif len(user.company_ids) > 1 and user.id not in group_multi_company.users.ids:
      group_multi_company.write({'users': [(4, user.id)]})

      # Publish message to subscriber
      pubsub = PubSub()

      // Here I used own middleware service which is used for CRUD opertion on
      Odoo model
      // Below API return record of model 'res.users'
      // Here user.id return 67
      req = requests.get('http://localhost:8080/users/' + str(user.id))
      fetch_user = req.text // response return user not found because record nor save in table
      result = pubsub.publish_message_on_topic(self.project_id, self.topic_name, fetch_user)
      return user


      In create function user created & its return id in user variable but its not save in table until 'return user'(last line of function) not run. I don't know how create functionality worked in Odoo?



      So,I search on any event triggered when record created/updated so I will implement my pubsub logic to that function.



      Any help or suggestion?



      Thank you.







      python odoo-11






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Jan 2 at 12:58









      Girish GhodaGirish Ghoda

      539




      539
























          1 Answer
          1






          active

          oldest

          votes


















          0














          odoo works like transaction untill transaction is not completed it didnot commit it.odoo calls create function and do all its functionality but it didnot reflect in database untill it returns the value, you will get its values in function but it didnot commit this in database untill function returns the value






          share|improve this answer
























          • Thanks for the reply. Then any other solution for getting event after created/store record in the database? Our middleware API service which points to Odoo server for CRUD operations. After created record, I called our service API to fetch that record via record id and response published to pubsub topic.

            – Girish Ghoda
            Jan 4 at 7:27











          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%2f54006826%2fcall-funtion-when-odoo-record-created%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          odoo works like transaction untill transaction is not completed it didnot commit it.odoo calls create function and do all its functionality but it didnot reflect in database untill it returns the value, you will get its values in function but it didnot commit this in database untill function returns the value






          share|improve this answer
























          • Thanks for the reply. Then any other solution for getting event after created/store record in the database? Our middleware API service which points to Odoo server for CRUD operations. After created record, I called our service API to fetch that record via record id and response published to pubsub topic.

            – Girish Ghoda
            Jan 4 at 7:27
















          0














          odoo works like transaction untill transaction is not completed it didnot commit it.odoo calls create function and do all its functionality but it didnot reflect in database untill it returns the value, you will get its values in function but it didnot commit this in database untill function returns the value






          share|improve this answer
























          • Thanks for the reply. Then any other solution for getting event after created/store record in the database? Our middleware API service which points to Odoo server for CRUD operations. After created record, I called our service API to fetch that record via record id and response published to pubsub topic.

            – Girish Ghoda
            Jan 4 at 7:27














          0












          0








          0







          odoo works like transaction untill transaction is not completed it didnot commit it.odoo calls create function and do all its functionality but it didnot reflect in database untill it returns the value, you will get its values in function but it didnot commit this in database untill function returns the value






          share|improve this answer













          odoo works like transaction untill transaction is not completed it didnot commit it.odoo calls create function and do all its functionality but it didnot reflect in database untill it returns the value, you will get its values in function but it didnot commit this in database untill function returns the value







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Jan 4 at 4:35









          AkshayAkshay

          1364




          1364













          • Thanks for the reply. Then any other solution for getting event after created/store record in the database? Our middleware API service which points to Odoo server for CRUD operations. After created record, I called our service API to fetch that record via record id and response published to pubsub topic.

            – Girish Ghoda
            Jan 4 at 7:27



















          • Thanks for the reply. Then any other solution for getting event after created/store record in the database? Our middleware API service which points to Odoo server for CRUD operations. After created record, I called our service API to fetch that record via record id and response published to pubsub topic.

            – Girish Ghoda
            Jan 4 at 7:27

















          Thanks for the reply. Then any other solution for getting event after created/store record in the database? Our middleware API service which points to Odoo server for CRUD operations. After created record, I called our service API to fetch that record via record id and response published to pubsub topic.

          – Girish Ghoda
          Jan 4 at 7:27





          Thanks for the reply. Then any other solution for getting event after created/store record in the database? Our middleware API service which points to Odoo server for CRUD operations. After created record, I called our service API to fetch that record via record id and response published to pubsub topic.

          – Girish Ghoda
          Jan 4 at 7:27




















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54006826%2fcall-funtion-when-odoo-record-created%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

          Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

          Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

          A Topological Invariant for $pi_3(U(n))$