Skip to Content
Menu
This question has been flagged
2 Replies
2320 Rodiniai

Hello everyone,


I'm working on a project in Odoo and would like to add a specific feature to the sales order system. I need to create a subsection within each product line in the sales order, where I can add related products or additional services. Additionally, I would like the total of the main section to include the total of the subsections automatically.


Has anyone done something similar or have any suggestions on how I can implement this feature? I'm particularly interested in knowing how I can set up the subsections and how to ensure that the total of the main section is updated correctly based on the totals of the subsections.


Thank you in advance for any guidance or suggestions you can offer!

Portretas
Atmesti
Best Answer

here i give you example you can try this way:
from odoo import models, fields, api


class SaleOrderLineSubsection(models.Model):

    _name = 'sale.order.line.subsection'


    name = fields.Char(string='Name')

    product_id = fields.Many2one('product.product', string='Product')

    quantity = fields.Float(string='Quantity')

    price_unit = fields.Float(string='Unit Price')

    subtotal = fields.Float(string='Subtotal', compute='_compute_subtotal')


    @api.depends('quantity', 'price_unit')

    def _compute_subtotal(self):

        for subsection in self:

            subsection.subtotal = subsection.quantity * subsection.price_unit


class SaleOrderLine(models.Model):

    _inherit = 'sale.order.line'


    subsection_ids = fields.One2many('sale.order.line.subsection', 'order_line_id', string='Subsections')

    total_subsections = fields.Float(string='Total Subsections', compute='_compute_total_subsections')


    @api.depends('subsection_ids.subtotal')

    def _compute_total_subsections(self):

        for line in self:

            line.total_subsections = sum(sub.subtotal for sub in line.subsection_ids)


    @api.onchange('subsection_ids')

    def _onchange_subsections(self):

        self.price_subtotal = sum(sub.subtotal for sub in self.subsection_ids)


Portretas
Atmesti
Autorius Best Answer

Thank you!

Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
3
vas. 25
1796
1
gruod. 24
1994
2
kov. 24
2864
0
rugs. 23
1447
1
rugs. 23
1437