تخطي للذهاب إلى المحتوى
القائمة
لقد تم الإبلاغ عن هذا السؤال
2 الردود
2316 أدوات العرض

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!

الصورة الرمزية
إهمال
أفضل إجابة

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)


الصورة الرمزية
إهمال
الكاتب أفضل إجابة

Thank you!

الصورة الرمزية
إهمال
المنشورات ذات الصلة الردود أدوات العرض النشاط
3
فبراير 25
1794
1
ديسمبر 24
1994
2
مارس 24
2864
0
سبتمبر 23
1447
1
سبتمبر 23
1435