Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

odoo v11 (Qweb) how to store data in a variable after looping so that you could compare it

Subscriure's

Get notified when there's activity on this post

This question has been flagged
qwebreportingconditionalloopodoov11
1 Respondre
8193 Vistes
Avatar
Abdullah

Here is simple loop which i am using


<t t-foreach="docs" t-as="o">
<td colspan="2">
<span t-field="o.vendor" />
</td>
</t>
As this i a report of tree view i want to check if a vendor name is printed before it must not print again. So how to do that?
0
Avatar
Descartar
Avatar
Muhammad Anees
Best Answer

See the code. I declared a variable total like t-set="total"

<tr>
  <td class="col-xs-6 bg-light">Total</td> 
<td class="col-xs-6 text-center">  
<t t-set="total" t-value="o.per_diem + o.housing_deduction + o.equivalent_air_ticket + o.airport_parking"/> 
<t t-esc="total" t-options='{"widget": "float", "precision": 2}'/>       
</td> 
</tr>
1
Avatar
Descartar
Abdullah
Autor

hello sir thanks for replying you are really a teacher for me :D Just one question how would you check if the value of o.per_diem which you printed in the first line is repeating itself or not

Muhammad Anees

Repeating means? Its in a loop <t t-foreach="docs" t-as="o"> print it in the foreach loop or outside.

Use if like <span t-field="o.per_diem" />

Muhammad Anees

<t t-if="o.per_diem>100">

<span t-field="o.city" />

</t>

Abdullah
Autor

Sir i have tree view as you know i select lines and print them and it shows me the comparison of different prices quoted by the vendor for different products. But for each product vendor name prints itself again. I want to see in the selected lines that if vendor's name is same as before then it must not print again

Muhammad Anees

You need group by vendor.. here is an example

https://www.odoo.com/forum/help-1/question/how-to-group-by-product-category-in-qweb-report-102920

Abdullah
Autor

Thank you sir i will try and let you know in a moment. You are always a big help

Abdullah
Autor

sir this is giving me this error " 'str' object has no attribute 'vendor'"

i am using following code as you have suggested

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

<t t-foreach="docs" t-as="o">

<t t-set="vendor_list" t-value="vendor_list+[o.vendor]"/>

</t>

<t t-foreach="set(vendor_list)" t-as="category">

<div><strong t-esc="category.vendor"/></div>

<t t-foreach="docs" t-as="o">

<t t-if="category.vendor==o.vendor">

<div><span t-field="o.vendor"/></div>

</t>

</t>

</t>

Please dont get irritated as i am bothering you again and again but kindly help me for this last time

Muhammad Anees

Share your custom model code here...what fields it has. What is relation with res_partner?

Abdullah
Autor

i am fetching data from the data base so i have made partner too as a Char field

class PostgresReport(models.Model):

_name = 'purchase.comp'

_auto = False

name = fields.Char(string = 'Purchase Order')

origin = fields.Char(string ='Purchase Agreement')

date_order = fields.Datetime('Order Date', index=True, copy=False)

state = fields.Selection([

('draft', 'RFQ'),

('sent', 'RFQ Sent'),

('to approve', 'To Approve'),

('purchase', 'Purchase Order'),

('done', 'Locked'),

('cancel', 'Cancelled')

], string='Status', readonly=True, index=True, copy=False, default='draft', track_visibility='onchange')

requisition_id = fields.Char(string='requisition_id')

product_id = fields.Char(string='Product')

product_qty = fields.Float(string='Quantity')

price_unit = fields.Float(string='Unit Price')

price_subtotal = fields.Float(string='Subtotal')

vendor = fields.Char(string='Vendor')

currency_id = fields.Char('Currency')

@api.model_cr

def init(self, _logger=None):

""" Event Question main report """

query = []

tools.drop_view_if_exists(self._cr, 'purchase_comp')

view = self._cr.execute(""" CREATE VIEW purchase_comp AS (

SELECT

b.id as id,

a.name as "name",

a.origin as "origin",

a.requisition_id as "requisition_id",

a.date_order as "date_order",

a.state as "state",

b.name as "product_id",

b.order_id as "order_id",

b.product_qty as "product_qty",

b.price_unit as "price_unit",

b.price_subtotal as "price_subtotal",

c.display_name as "vendor",

d.name as "currency_id"

FROM public.purchase_order as a

inner join

public.purchase_order_line as b

on a.id = b.order_id

inner join

public.res_partner as c

on a.partner_id = c.id

inner join

public.res_currency as d

on d.id = b.currency_id

WHERE a.origin != ''

order by a.name

)""")

Muhammad Anees

The code you shared is for Odoo Business Intelligence where you select measures and analyze data, like lot of odoo standard reports. But the report that you are trying to develop is a simple PDF report.

Abdullah
Autor

so i cannot group it by vendor in qweb? Not possible?

Muhammad Anees

Try to group by in your above sql query like order by vendor.... Test your sql query in postgresql to get your required results.

Abdullah
Autor

sir i have tried that all and i am able to remove duplicates from the report by using this

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

<t t-foreach="docs" t-as="o">

<t t-set="product_names" t-value="product_names+[o.product_id]"/>

</t>

<t t-foreach="set(product_names)" t-as="bat">

<tr class="row2">

<td>

<span t-field="bat.id" />

<span t-field="bat.name" />

</td>

</tr>

</t>

But this code works for Many2one field only and i have float fields as well so m at a dead end now.

Abdullah
Autor

sir can you tell what this means?

sale_order_id = request.session.get('sale_last_order_id')

i found this is website_sale module in controller.

I also have a report made from controller which opens in website. If i somehow able to download it in pdf my work will be done. if you know any work around for downloading pdf from website

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
odoo (v11) how to start a loop and put a condition in it to check if a variable is repeating and it is repeating then it must not print
qweb reporting conditional loop odoov11
Avatar
0
de nov. 19
3935
Report for Product move list view in inventory module.(Odoo v11) Solved
qweb inventory reporting reports odoov11
Avatar
Avatar
Avatar
4
d’ag. 20
5923
Get values of controller into another controller (odoo v11)
web qweb reporting controllers odoov11
Avatar
0
de nov. 19
4016
How can I display all tasks (including completed ones) in a QWeb report in Odoo?
qweb reporting
Avatar
Avatar
2
de set. 24
3037
Loop through a group list with Qweb in Odoo17 Solved
qweb loop
Avatar
Avatar
2
de març 24
2251
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now