Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
1 Rispondi
6636 Visualizzazioni

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?
Avatar
Abbandona
Risposta migliore

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>
Avatar
Abbandona
Autore

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

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" />

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

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

</t>

Autore

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

Autore

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

Autore

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

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

Autore

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

)""")

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.

Autore

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

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

Autore

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.

Autore

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

Post correlati Risposte Visualizzazioni Attività
0
nov 19
2925
4
ago 20
4880
0
nov 19
3016
2
set 24
1196
2
mar 24
1121