odoo 10 custom report ..sum lines qty..by product_id












1















odoo 10 report...question ...
why get_qty can't send data to docargs?
i want lines data...qty sum...by product_id is same...
why xml t-foreach="data" can get any data for me



class ReportStockInventorySummary(models.AbstractModel):
_name = 'report.stock.inventory.summary'

def get_qty(self, docids):
docs = self.env["stock.inventory"].browse(docids)
lines = self.env["stock.inventory.line"].search([('inventory_id', '=', docs.id)])
data = list()
show_data = list()
for x in lines:
data.append({
"line_location_id": x.location_id,
"line_product_id": x.product_id,
"line_product_qty": x.product_qty,
})

for i, g in groupby(sorted(data), key=lambda x: x['line_product_id']):
show_data.append([i, sum(v['line_product_qty'] for v in g)])

@api.multi
def render_html(self, docids, data):
report = self.env['report']
self.model = self.env.context.get('active_model')
docs = self.env["stock.inventory"].browse(docids)


docargs = {
'doc_ids': docids,
'doc_model': self.model,
'docs': docs,
'data': self.get_qty //* i want sum product_qty by product_id *//
}
return report.render("stock_inventory_report.report_stock_inventory_template", docargs)

<?xml version="1.0"?>
<odoo>
<data>
<template id="report_stock_inventory_template">
<t t-call="report.html_container">
<t t-foreach="docs" t-as="o">
<div class="page">
<h2>Report title</h2>
<p>This object's name is
<span t-field="o.name"/>
</p>
<table class="table table-condensed">
<thead>
<tr>
<th><strong>Location</strong></th>
<th><strong>Product</strong></th>
<th class="text-right"><strong>Quantity</strong></th>
</tr>
</thead>
<!---- why t-foreach="data" cant show any data for me -->
<tr t-foreach="data" t-as="line">
<td><span t-esc="line['line_location_id']" /></td>
<td><span t-esc="line['line_product_id']" /></td>
<td><span t-esc="line['line_product_qty']" /></td>
</tr>


<tr>
<td></td>
</tr>
</table>
</div>
</t>
</t>
</template>
</data>
</odoo>


I want from stock.inventory.lines in qweb display data and field (location_id, product_id, product_qty) what do I need to change in above py and how do I create view?

Any similar examples for a beginner?










share|improve this question



























    1















    odoo 10 report...question ...
    why get_qty can't send data to docargs?
    i want lines data...qty sum...by product_id is same...
    why xml t-foreach="data" can get any data for me



    class ReportStockInventorySummary(models.AbstractModel):
    _name = 'report.stock.inventory.summary'

    def get_qty(self, docids):
    docs = self.env["stock.inventory"].browse(docids)
    lines = self.env["stock.inventory.line"].search([('inventory_id', '=', docs.id)])
    data = list()
    show_data = list()
    for x in lines:
    data.append({
    "line_location_id": x.location_id,
    "line_product_id": x.product_id,
    "line_product_qty": x.product_qty,
    })

    for i, g in groupby(sorted(data), key=lambda x: x['line_product_id']):
    show_data.append([i, sum(v['line_product_qty'] for v in g)])

    @api.multi
    def render_html(self, docids, data):
    report = self.env['report']
    self.model = self.env.context.get('active_model')
    docs = self.env["stock.inventory"].browse(docids)


    docargs = {
    'doc_ids': docids,
    'doc_model': self.model,
    'docs': docs,
    'data': self.get_qty //* i want sum product_qty by product_id *//
    }
    return report.render("stock_inventory_report.report_stock_inventory_template", docargs)

    <?xml version="1.0"?>
    <odoo>
    <data>
    <template id="report_stock_inventory_template">
    <t t-call="report.html_container">
    <t t-foreach="docs" t-as="o">
    <div class="page">
    <h2>Report title</h2>
    <p>This object's name is
    <span t-field="o.name"/>
    </p>
    <table class="table table-condensed">
    <thead>
    <tr>
    <th><strong>Location</strong></th>
    <th><strong>Product</strong></th>
    <th class="text-right"><strong>Quantity</strong></th>
    </tr>
    </thead>
    <!---- why t-foreach="data" cant show any data for me -->
    <tr t-foreach="data" t-as="line">
    <td><span t-esc="line['line_location_id']" /></td>
    <td><span t-esc="line['line_product_id']" /></td>
    <td><span t-esc="line['line_product_qty']" /></td>
    </tr>


    <tr>
    <td></td>
    </tr>
    </table>
    </div>
    </t>
    </t>
    </template>
    </data>
    </odoo>


    I want from stock.inventory.lines in qweb display data and field (location_id, product_id, product_qty) what do I need to change in above py and how do I create view?

    Any similar examples for a beginner?










    share|improve this question

























      1












      1








      1








      odoo 10 report...question ...
      why get_qty can't send data to docargs?
      i want lines data...qty sum...by product_id is same...
      why xml t-foreach="data" can get any data for me



      class ReportStockInventorySummary(models.AbstractModel):
      _name = 'report.stock.inventory.summary'

      def get_qty(self, docids):
      docs = self.env["stock.inventory"].browse(docids)
      lines = self.env["stock.inventory.line"].search([('inventory_id', '=', docs.id)])
      data = list()
      show_data = list()
      for x in lines:
      data.append({
      "line_location_id": x.location_id,
      "line_product_id": x.product_id,
      "line_product_qty": x.product_qty,
      })

      for i, g in groupby(sorted(data), key=lambda x: x['line_product_id']):
      show_data.append([i, sum(v['line_product_qty'] for v in g)])

      @api.multi
      def render_html(self, docids, data):
      report = self.env['report']
      self.model = self.env.context.get('active_model')
      docs = self.env["stock.inventory"].browse(docids)


      docargs = {
      'doc_ids': docids,
      'doc_model': self.model,
      'docs': docs,
      'data': self.get_qty //* i want sum product_qty by product_id *//
      }
      return report.render("stock_inventory_report.report_stock_inventory_template", docargs)

      <?xml version="1.0"?>
      <odoo>
      <data>
      <template id="report_stock_inventory_template">
      <t t-call="report.html_container">
      <t t-foreach="docs" t-as="o">
      <div class="page">
      <h2>Report title</h2>
      <p>This object's name is
      <span t-field="o.name"/>
      </p>
      <table class="table table-condensed">
      <thead>
      <tr>
      <th><strong>Location</strong></th>
      <th><strong>Product</strong></th>
      <th class="text-right"><strong>Quantity</strong></th>
      </tr>
      </thead>
      <!---- why t-foreach="data" cant show any data for me -->
      <tr t-foreach="data" t-as="line">
      <td><span t-esc="line['line_location_id']" /></td>
      <td><span t-esc="line['line_product_id']" /></td>
      <td><span t-esc="line['line_product_qty']" /></td>
      </tr>


      <tr>
      <td></td>
      </tr>
      </table>
      </div>
      </t>
      </t>
      </template>
      </data>
      </odoo>


      I want from stock.inventory.lines in qweb display data and field (location_id, product_id, product_qty) what do I need to change in above py and how do I create view?

      Any similar examples for a beginner?










      share|improve this question














      odoo 10 report...question ...
      why get_qty can't send data to docargs?
      i want lines data...qty sum...by product_id is same...
      why xml t-foreach="data" can get any data for me



      class ReportStockInventorySummary(models.AbstractModel):
      _name = 'report.stock.inventory.summary'

      def get_qty(self, docids):
      docs = self.env["stock.inventory"].browse(docids)
      lines = self.env["stock.inventory.line"].search([('inventory_id', '=', docs.id)])
      data = list()
      show_data = list()
      for x in lines:
      data.append({
      "line_location_id": x.location_id,
      "line_product_id": x.product_id,
      "line_product_qty": x.product_qty,
      })

      for i, g in groupby(sorted(data), key=lambda x: x['line_product_id']):
      show_data.append([i, sum(v['line_product_qty'] for v in g)])

      @api.multi
      def render_html(self, docids, data):
      report = self.env['report']
      self.model = self.env.context.get('active_model')
      docs = self.env["stock.inventory"].browse(docids)


      docargs = {
      'doc_ids': docids,
      'doc_model': self.model,
      'docs': docs,
      'data': self.get_qty //* i want sum product_qty by product_id *//
      }
      return report.render("stock_inventory_report.report_stock_inventory_template", docargs)

      <?xml version="1.0"?>
      <odoo>
      <data>
      <template id="report_stock_inventory_template">
      <t t-call="report.html_container">
      <t t-foreach="docs" t-as="o">
      <div class="page">
      <h2>Report title</h2>
      <p>This object's name is
      <span t-field="o.name"/>
      </p>
      <table class="table table-condensed">
      <thead>
      <tr>
      <th><strong>Location</strong></th>
      <th><strong>Product</strong></th>
      <th class="text-right"><strong>Quantity</strong></th>
      </tr>
      </thead>
      <!---- why t-foreach="data" cant show any data for me -->
      <tr t-foreach="data" t-as="line">
      <td><span t-esc="line['line_location_id']" /></td>
      <td><span t-esc="line['line_product_id']" /></td>
      <td><span t-esc="line['line_product_qty']" /></td>
      </tr>


      <tr>
      <td></td>
      </tr>
      </table>
      </div>
      </t>
      </t>
      </template>
      </data>
      </odoo>


      I want from stock.inventory.lines in qweb display data and field (location_id, product_id, product_qty) what do I need to change in above py and how do I create view?

      Any similar examples for a beginner?







      python odoo odoo-10






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 15 '18 at 8:27









      user2655334user2655334

      113




      113
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You're binding the method get_qty to data, but you should call it instead.



          'data': self.get_qty(doc_ids)



          Even better is not to use data key, because it already is used by another process. Just make your own key and use it in your report template instead of data:



          'get_qty': self.get_qty(doc_ids)



          And your method is not returning anything resp. None. I think show_data is your return result so just return it.



          def get_qty(self, docids):
          show_data =
          # ...
          return show_data





          share|improve this answer


























          • Thanks....I have tried 'data': show_data ...But...result is None..only docs data show in my pdf data

            – user2655334
            Nov 15 '18 at 12:06













          • I've edited my answer a bit.

            – CZoellner
            Nov 15 '18 at 12:56











          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%2f53315158%2fodoo-10-custom-report-sum-lines-qty-by-product-id%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














          You're binding the method get_qty to data, but you should call it instead.



          'data': self.get_qty(doc_ids)



          Even better is not to use data key, because it already is used by another process. Just make your own key and use it in your report template instead of data:



          'get_qty': self.get_qty(doc_ids)



          And your method is not returning anything resp. None. I think show_data is your return result so just return it.



          def get_qty(self, docids):
          show_data =
          # ...
          return show_data





          share|improve this answer


























          • Thanks....I have tried 'data': show_data ...But...result is None..only docs data show in my pdf data

            – user2655334
            Nov 15 '18 at 12:06













          • I've edited my answer a bit.

            – CZoellner
            Nov 15 '18 at 12:56
















          0














          You're binding the method get_qty to data, but you should call it instead.



          'data': self.get_qty(doc_ids)



          Even better is not to use data key, because it already is used by another process. Just make your own key and use it in your report template instead of data:



          'get_qty': self.get_qty(doc_ids)



          And your method is not returning anything resp. None. I think show_data is your return result so just return it.



          def get_qty(self, docids):
          show_data =
          # ...
          return show_data





          share|improve this answer


























          • Thanks....I have tried 'data': show_data ...But...result is None..only docs data show in my pdf data

            – user2655334
            Nov 15 '18 at 12:06













          • I've edited my answer a bit.

            – CZoellner
            Nov 15 '18 at 12:56














          0












          0








          0







          You're binding the method get_qty to data, but you should call it instead.



          'data': self.get_qty(doc_ids)



          Even better is not to use data key, because it already is used by another process. Just make your own key and use it in your report template instead of data:



          'get_qty': self.get_qty(doc_ids)



          And your method is not returning anything resp. None. I think show_data is your return result so just return it.



          def get_qty(self, docids):
          show_data =
          # ...
          return show_data





          share|improve this answer















          You're binding the method get_qty to data, but you should call it instead.



          'data': self.get_qty(doc_ids)



          Even better is not to use data key, because it already is used by another process. Just make your own key and use it in your report template instead of data:



          'get_qty': self.get_qty(doc_ids)



          And your method is not returning anything resp. None. I think show_data is your return result so just return it.



          def get_qty(self, docids):
          show_data =
          # ...
          return show_data






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Nov 15 '18 at 12:55

























          answered Nov 15 '18 at 8:45









          CZoellnerCZoellner

          7,15331529




          7,15331529













          • Thanks....I have tried 'data': show_data ...But...result is None..only docs data show in my pdf data

            – user2655334
            Nov 15 '18 at 12:06













          • I've edited my answer a bit.

            – CZoellner
            Nov 15 '18 at 12:56



















          • Thanks....I have tried 'data': show_data ...But...result is None..only docs data show in my pdf data

            – user2655334
            Nov 15 '18 at 12:06













          • I've edited my answer a bit.

            – CZoellner
            Nov 15 '18 at 12:56

















          Thanks....I have tried 'data': show_data ...But...result is None..only docs data show in my pdf data

          – user2655334
          Nov 15 '18 at 12:06







          Thanks....I have tried 'data': show_data ...But...result is None..only docs data show in my pdf data

          – user2655334
          Nov 15 '18 at 12:06















          I've edited my answer a bit.

          – CZoellner
          Nov 15 '18 at 12:56





          I've edited my answer a bit.

          – CZoellner
          Nov 15 '18 at 12:56




















          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%2f53315158%2fodoo-10-custom-report-sum-lines-qty-by-product-id%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

          Xamarin.iOS Cant Deploy on Iphone

          Glorious Revolution

          Dulmage-Mendelsohn matrix decomposition in Python