Skip to Content
मेन्यू
This question has been flagged
3 Replies
110 Views

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

Avatar
Discard

What is "the code"?

Author

In Advanced Properties, Compute

I mean this

Best Answer

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
Discard
Best Answer

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
Discard
Best Answer

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
Discard
Related Posts Replies Views Activity
1
अक्तू॰ 24
2436
2
सित॰ 25
2883
1
अग॰ 25
2294
1
अग॰ 25
1227
0
जुल॰ 25
1248