Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
2329 Tampilan

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!

Avatar
Buang
Jawaban Terbai

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)


Avatar
Buang
Penulis Jawaban Terbai

Thank you!

Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
3
Feb 25
1800
1
Des 24
1996
2
Mar 24
2878
0
Sep 23
1447
1
Sep 23
1439