Reputation: 123
What I want is simple, but I have no idea how to do it, I would be glad if anyone could help me
So I have this One2many tree view :
For this model :
class StockInventoryDeGroupeLine(models.Model):
_name = 'stock.inventory.degroupe.line'
_order = 'sequence'
stock_inventory_id = fields.Many2one(
'stock.inventory',
string='stock',
)
product_id = fields.Many2one(
'product.product',
string='Article',
)
quantity = fields.Float(
string='Quantité',
)
display_type = fields.Selection([
('line_section', "Section"),
('line_emplacement', "Emplacement"),
('line_note', "Note"),],
default=False,
help="Technical field for UX purpose.")
name = fields.Text(
string='Description',
required=False,
)
sequence = fields.Integer(
string='Sequence',
default=10,
)
location_id = fields.Many2one(
'stock.location',
string='Emplacement',
)
prod_lot_id = fields.Many2one(
'stock.production.lot',
'Lot/numéro de sérié',
)
product_tracking = fields.Selection(
'Suivi',
related='product_id.tracking',
readonly=True)
_sql_constraints = [('unique_seq','UNIQUE(sequence)',"La sequence doit être unique"),]
@api.onchange('product_id', 'sequence')
def onchange_product_id(self):
for record in self:
if record.display_type == False or record.display_type == 'line_emplacement' :
if record.sequence == 10 :
record.location_id = record.stock_inventory_id.location_id
return
else :
new_sequence = record.sequence -1
while new_sequence >= 10 :
for record2 in record.stock_inventory_id.degroupee_line_ids :
if record2.sequence == new_sequence :
if record2.display_type != 'line_section':
record.location_id = record2.location_id
return
new_sequence -= 1
@api.onchange('product_id','location_id','name')
def onchange_sequence(self):
for record in self :
record.sequence += 1
When I'm in the editing mode, I want to disable sort by article, lot, emplacement... To make it simple, I want to have it sorted only by sequence
Upvotes: 1
Views: 922
Reputation: 99
may be it will hepls you...
put your sequence field in one2many tree view as invisible..
Upvotes: 1