【发布时间】:2021-06-17 10:54:38
【问题描述】:
我想要的很简单,但我不知道该怎么做,如果有人可以帮助我,我会很高兴 所以我有这个 One2many 树视图:
对于这个模型:
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
当我处于编辑模式时,我想禁用按文章、批次、位置排序... 为了简单起见,我想让它只按顺序排序
【问题讨论】:
-
我认为您的字段不是 many2one,而是 one2many 字段,并且记录排序为您创建的最新记录将在最后一条记录中。
-
对不起,这是一个错误,我已修复它,当我按“文章”排序时,尝试添加一条新记录,它弄乱了我的功能
-
我很困惑。告诉我你到底想做什么和需要什么。我想我可以帮助你
-
你的函数有错误?你有两个函数,哪个函数出错了?哪个错误?
-
当我添加一个新的“文章”时,它会使用上一行的“Emplacement”或默认的“Emplacement”,正如您在“onchange”函数中看到的那样......但如果我排序通过'Article'然后添加一个新行它采用默认的'Emplacement'
标签: listview odoo many-to-one odoo-12