Siirry sisältöön
Menu
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Tämä kysymys on merkitty
2 Vastaukset
2160 Näkymät

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
Hylkää
Paras vastaus

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
Hylkää
Tekijä Paras vastaus

Thank you!

Avatar
Hylkää
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
3
helmik. 25
1616
1
jouluk. 24
1818
2
maalisk. 24
2695
0
syysk. 23
1324
1
syysk. 23
1343