Skip to Content
Menu
This question has been flagged
3849 Views

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
Discard

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

Related Posts Replies Views Activity
9
Jun 23
12163
2
Jan 22
3178
2
Dec 21
6938
0
Jun 21
1395
0
Feb 21
1976