Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
4 Replies
165 Tampilan

I Want The Code In Compute because I Test Every Step, but it doesn't work
And thank you for helping me

Avatar
Buang

What is "the code"?

Penulis

In Advanced Properties, Compute

I mean this

Jawaban Terbai

Hi,


Try the following code,


class SaleOrderLine(models.Model):

    """ Class for inherited model sale order line. Contains a field for line

            numbers and a function for computing line numbers.

    """


    _inherit = 'sale.order.line'


    sequence_number = fields.Integer(string='#', compute='_compute_sequence_number', help='Line Numbers')


    @api.depends('sequence', 'order_id')

    def _compute_sequence_number(self):

        """Function to compute line numbers"""

        for order in self.mapped('order_id'):

            sequence_number = 1

            for lines in order.order_line:

                if lines.display_type:

                    lines.sequence_number = sequence_number

                    sequence_number += 0

                else:

                    lines.sequence_number = sequence_number

                    sequence_number += 1


Hope it helps

Avatar
Buang
Jawaban Terbai

Hi Yuossef,

class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'

sl_no = fields.Integer(string="Sl. No.", compute="_compute_sl_no")

@api.depends('order_id.order_line', 'order_id.order_line.display_type', 'order_id.order_line.sequence')
def _compute_sl_no(self):
for order in self.mapped('order_id'):
index = 0
for line in order.order_line:
if not line.display_type:
index += 1
line.sl_no = index
else:
line.sl_no = False



Hope this helps.

Avatar
Buang
Jawaban Terbai

from odoo import models, fields, api


class SaleOrderLine(models.Model):

    _inherit = 'sale.order.line'


    sequence_number = fields.Char(string='Sequence', compute='_compute_sequence')


    @api.depends('order_id', 'order_id.state')

    def _compute_sequence(self):

        for line in self:

            if line.order_id:

                sequence = line.order_id.sequence_next()

                line.sequence_number = sequence


sequence_number is a computed field that generates the sequence.

order_id.sequence_next() can be used to fetch the next available sequence for the order.

Make sure you also have a sequence defined for the sale.order model or use the built-in ir.sequence model to manage sequence generation. Adjust the logic as needed based on your specific requirements.

Avatar
Buang
Jawaban Terbai

Add a new field in so and add the automation action 
i = 1

for line in record.order_line.sorted(key=lambda l: l.sequence):

    if line.display_type not in ('line_section', 'line_note'):

        line.write({'x_studio_so_line_number': i})

        i += 1

and this code for invoce 
i = 1

for line in record.invoice_line_ids.sorted(key=lambda l: l.sequence):

    if line.display_type not in ('line_section', 'line_note'):

        line.write({'x_studio_line': i})

        i += 1



Avatar
Buang
Post Terkait Replies Tampilan Aktivitas
1
Okt 24
2456
2
Sep 25
2904
1
Agu 25
2304
1
Agu 25
1240
0
Jul 25
1255