Skip to Content
Menu
This question has been flagged
1540 Views


Hello,

I am working on Odoo 11 and I am trying to display the values ​​of a 2D list ( that I have created in my model) in the form view of quotes / orders.


Here is 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:
                        if line.layout_category_id not in stockSection:
                            stockSection.append(line.layout_category_id)
                            nbSection += 1

                
                col = 3     # Nombre de colognes
                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:
                    if line.layout_category_id:
                        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:
                    if line.layout_category_id:
                        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
                        return listSection
                    else:
                        return "test"
                

 


If anyone knows how to do it I would be very grateful !

Avatar
Discard
Related Posts Replies Views Activity
9
Jun 23
11130
2
Jan 22
2733
2
Dec 21
6269
0
Jun 21
1007
0
Feb 21
3325