Zum Inhalt springen
Menü
Sie müssen registriert sein, um mit der Community zu interagieren.
Diese Frage wurde gekennzeichnet
4277 Ansichten

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
Verwerfen

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

Verknüpfte Beiträge Antworten Ansichten Aktivität
9
Juni 23
13013
2
Jan. 22
3812
2
Dez. 21
7833
0
Juni 21
1904
0
Feb. 21
2506