PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, May 10, 2022

[FIXED] How do I create a table showing a combination of product variants in qweb report?

 May 10, 2022     odoo, product, python, qweb, report     No comments   

Issue

I would like to display my products in tables depending on what variants they have. If a product has two attributes, I would like it displayed in a table with the values (of the attributes with the least values) as the column headers, and the other attribute values headers as the row headers. If a product has one or no attributes, then the attribute values should be the row headers. If a product has more than two attributes, the remainder attributes should form a separate table adjacent to the original table.

I managed to get the row headers working, but couldn't get the column headers and the prices of each product variant working. Here is my code:

<?xml version="1.0"?>

<t t-name="product.report_menu">
  <t t-call="web.html_container">
    <t t-call="web.internal_layout">

      <div class="page" style="height: 28cm; width: 21cm; font-family: Patrick Hand;">

        <table style="width: 100%; padding-top: 30px">
          <tbody>
            <tr>

              <td valign="top" style="width: 75%; border: solid 2px orange;padding-left: 20px;padding-right: 20px;">
                <div style="min-height: 29.5cm;">

                  <!-- setting default groupings to nil-->
                  <t t-set="product_category" t-value="[]" />
                  <t t-set="attribute_category" t-value="[]" />
                  <t t-set="name_category" t-value="[]" />
                  <t t-set="attribute_value_name_category" t-value="[]" />
                  <t t-set="price" t-value="[]" />
                  <t t-set="pricf" t-value="[]" />


                  <!-- setting default groupings to nil-->
                  <t t-foreach="docs" t-as="mpl">

                    <!-- setting grouping to the value of the product-->
                    <t t-set="product_category" t-value="product_category+[mpl.categ_id]" />
                  </t>


                  <!-- lines associated for grouping individual products based on category, i.e Cookies and all its variants  -->
                  <t t-foreach="set(product_category)" t-as="category">

                    <!-- product category name -->
                    <strong>
                                            <h3 t-esc="category.name" /> </strong>

                    <!-- setting grouping to the value of the product-->
                    <t t-foreach="docs" t-as="mpl">
                      <t t-set="name_category" t-value="name_category+[mpl.name]" />

                      <t t-set="price" t-value="price+[mpl.lst_price]" />


                      <t t-foreach="mpl.attribute_value_ids" t-as="attrib_value">
                        <t t-set="pricf" t-value="pricf+[mpl.lst_price]" />
                        <t t-set="attribute_category" t-value="attribute_category+[attrib_value.attribute_id]" />
                        <t t-set="attribute_value_name_category" t-value="attribute_value_name_category+[attrib_value]" />
                      </t>
                      <!-- <t t-foreach="mpl.attribute_value_ids" t-as="attrib_value"> -->

                    </t>

                    <t t-foreach="set(name_category)" t-as="namecate">
                      <strong>
                                                <h4 t-esc="namecate" /></strong>
                      <!-- if the products have attributes such as Size, create a size layout table -->



                      <table style="width: 50%; margin-bottom: 15px;">
                        <thead>
                          <th>Whatever...</th>
                          <th>att 1</th>
                          <th>att 2</th>
                          <th>att 4</th>
                        </thead>

                        <tbody>

                          <!-- setting grouping to the value of the product-->

                          <t t-foreach="set(attribute_category)" t-as="attric">
                            <t t-set="attribute_category" t-value="[]" />
                            <t t-if="not attric.name == 'Size'">
                              <strong>
                                    <h5 style="color: gray;" t-esc="'Comes in %ss of:' % (attric.name)" />
                                </strong>

                              <t t-foreach="set(attribute_value_name_category)" t-as="avnc">
                                <t t-if="avnc.attribute_id.name == attric.name">

                                  <t t-set="attribute_category" t-value="[]" />

                                  <tr>
                                    <td>
                                      <p t-esc="avnc.name" />
                                    </td>

                                    <t t-foreach="set(price)" t-as="pricee">
                                      <t t-if="not pricee == 0">

                                        <td>
                                          <span t-esc="'%s' % (pricee)" />
                                        </td>

                                      </t>
                                    </t>

                                  </tr>
                                </t>
                              </t>
                            </t>
                          </t>
                        </tbody>

                      </table>
                    </t>
                  </t>
                </div>
              </td>
            </tr>
          </tbody>
        </table>
      </div>
    </t>
  </t>

</t>

This is a list of the products and their attributes: products and their attribute

And this is the report generated: what report I am currently getting what report I am currently getting

This is my target:what I am trying to do

what I am trying to do

Could I please get some help, I am not sure how to proceed.

Thank you


Solution

I think that you better use a custom report parser to create groups of information to provide it to the report template in order to just iterate a custom data structure to print the previously prepared data into the needed tables and report output.

This seems to be a very complex report to be build against so many relation fields that will lead to so many iterations and boilerplate code at the qweb level.



Answered By - Axel Mendoza
Answer Checked By - Gilberto Lyons (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing