跳至內容
選單
此問題已被標幟
2 回覆
4796 瀏覽次數

I need to skip the section and note while creating a serial number in orderline, i made many modification,still its considering the section and notes as a line item, And its creating a serial number for section and notes.

My Python code :

from odoo import api, fields, models


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

@api.multi
@api.depends('order_line')
def _compute_maxim_line_sequence(self):

for sale in self:
for line in sale.order_line:
if line.name:
sale.maxim_line_sequence = (
maxim(sale.mapped('order_line.sequence') or [0]) + 1)

maxim_line_sequence = fields.Integer(
string='Maxim sequence in lines',
compute='_compute_maxim_line_sequence',
store=True
)

@api.multi
def _reset_sequence(self):
for rec in self:
current_sequence = 1
for line in rec.order_line:
if line.name:
line.sequence = current_sequence
current_sequence += 1

@api.multi
def write(self, line_values):
res = super(SaleOrder, self).write(line_values)
self._reset_sequence()
return res

@api.multi
def copy(self, default=None):
return super(SaleOrder,
self.with_context(keep_line_sequence=True)).copy(default)


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

# re-defines the field to change the default
sequence = fields.Integer(
help="Gives the sequence of this line when displaying the sale order.",
default=9999,
# related='x_seq_handle',
string="Sequence"
)

# displays sequence on the order line
sequence2 = fields.Integer(
help="Shows the sequence of this line in the sale order.",
related='sequence',
string="Line Number",
readonly=True,
store=True
)

@api.model
def create(self, values):
line = super(SaleOrderLine, self).create(values)
# We do not reset the sequence if we are copying a complete sale order
if self.env.context.get('keep_line_sequence'):
line.order_id._reset_sequence()
return line



here i can't able to restrict to create serial number to only order line contains product it.

can you please help me to do this.

頭像
捨棄

Hi Bharath,

I tried to follow your example but in this code (taken from module set_sequence_number) it does not work:

@api.depends('order_id.order_line', 'order_id.order_line.product_id')
def _sequence_ref(self):
for line in self:
no = 0
line.sequence_ref = no
for l in line.order_id.order_line:
no += 1
l.sequence_ref = no

I wrote the line "if not line.display_type:" in all the places but I do not get it to work. I also didn't get for this other code:

@api.depends('sequence', 'move_id')
def _compute_number(self):
for s in self:
s.index = 0
for
invoice in self.mapped('move_id'):
index = 1
if
invoice.invoice_line_ids:
for line in invoice.invoice_line_ids:
line.index = index
index += 1

I would be happy if you can show me where should the if not condition goes. I am using Odoo14.

Thank you.

最佳答案

did you find solution please?

頭像
捨棄
最佳答案

Hi,

If you need to exclude the sections and notes, you can add the condition like this:-  if not line.display_type , if the line is section or notes, the value will be set in this field.


You can see the field in the sale.order.line model:

display_type = fields.Selection([
('line_section', "Section"),
('line_note', "Note")], default=False, help="Technical field for UX purpose.")


Thanks

頭像
捨棄
作者

yeah already i tried this too, once again i tried this, still section are considered for serial number.

can you show me the code of how you set sequence number, will be fine if you can add that as a comment here, in the questions there seems a lot of code

作者

@api.multi

@api.depends('order_line')

def _compute_max_line_sequence(self):

for sale in self:

for line in sale.order_line:

if not line.display_type:

sale.max_line_sequence = (

max(sale.mapped('order_line.sequence') or [0]) + 1)

max_line_sequence = fields.Integer(

string='Max sequence in lines',

compute='_compute_max_line_sequence',

store=True

)

@api.multi

def _reset_sequence(self):

for rec in self:

current_sequence = 1

for line in rec.order_line:

if not line.display_type:

line.sequence = current_sequence

current_sequence += 1

i include the if not condition in these function

作者

Hi @Niyas Raphy, did you find any issue in below code.

what is the difference between these two functions

作者

first function is for generating a serial number

second is used for resetting the serial number sequence for usecase scenarios.

相關帖文 回覆 瀏覽次數 活動
1
4月 19
20271
0
1月 25
854
1
1月 24
13169
0
9月 20
3567
3
6月 25
1380