Overslaan naar inhoud
Menu
Je moet geregistreerd zijn om te kunnen communiceren met de community.
Deze vraag is gerapporteerd
4283 Weergaven

Hello,

I'm working on Odoo 11 and I'm trying to create a table that shows the total costs and total margins of the sections in the quotes / orders. I created the model but I don't know how to make a table in the views to retrieve the values that I calculated.


Here is the code for my model:


from odoo import fields, models, api

class SaleSectionMargin(models.Model):
    _inherit = 'sale.order'
    @api.depends('order_line', 'order_line.product_uom_qty', 'order_line.price_unit', 'order_line.discount', 'order_line.purchase_price', 'order_line.qty_invoiced')
    def _compute_margin_section(self):
        for record in self:
            if record.order_line:
               
                nbSection = 0
                stockSection = []
                
                for line in record.order_line:
                    if line.layout_category_id not in stockSection:
                        stockSection.append(line.layout_category_id)
                        nbSection += 1
               
                col = 3     
                listSection = [[0]*col for i in range(nbSection)]
                
                
                ligne = 0
                for section in stockSection:
                    listSection[ligne][0] = section
                    ligne += 1
                            
                
                for line in record.order_line:
                    L = 0
                    find = False
                    while find is False:
                        if listSection[L][0] == line.layout_category_id:
                            listSection[L][1] += line.purchase_price * line.product_uom_qty
                            find = True
                        L += 1
                
                
                for line in record.order_line:
                    find = False
                    L = 0
                    Totalcost = line.purchase_price*line.product_uom_qty  
                    discount = (Totalcost * line.discount)/100         
                    TotalPrice = line.price_unit*line.product_uom_qty   
                    Totalmargin = (TotalPrice-discount)-Totalcost  
                    
                    while find is False:
                        if listSection[L][0] == line.layout_category_id:
                            listSection[L][2] += Totalmargin
                            find = True
                        L += 1
 I have already been to see the tables created in the views of the sales and invoice modules but I do not understand how it works.

If anyone can help me that would be great!
Avatar
Annuleer

you may have a look at one of the numerous views already using tables, such as invoices, sales orders etc.

Gerelateerde posts Antwoorden Weergaven Activiteit
9
jun. 23
13017
2
jan. 22
3816
2
dec. 21
7841
0
jun. 21
1907
0
feb. 21
2509