将Many2一个变量移动到另一个模型



我有两个模型"库存;以及";废料";。有一个按钮。我想,如果我点击按钮数据移动到报废模型。没关系,我做到了。但除了一个变量;Many2one";。

所以当我点击按钮时,我得到了这个错误:;psycopg2.ProgrammingError:无法适应类型"ware.houses"odoo"。

这是我的库存模块。

class InventoryMenu(models.Model):
_name = "inventory.menu"
_description = "Inventory Menü"
ref_code = fields.Char(string="Referans Numarası: ", required=True, tracking=True, default="000000")
product_name = fields.Char(string="Ürün Adı: ", required=True, tracking=True,)
product_description = fields.Char(string="Ürün Tanımı: ", required=True, tracking=True,)
teslim_alan = fields.Char(string="Teslim Alan: ", required=True, tracking=True,)
teslim_eden = fields.Char(string="Teslim Eden: ", required=True, tracking=True,)
quantity = fields.Float(string="Miktar: ", required=True, tracking=True,)
price = fields.Float(string="Fiyat: ", required=True, tracking=True,)
unit_price = fields.Float(string="Birim Fiyat: ", compute="_unitPriceCalcuteFunc")
warehouse_id = fields.Many2one('ware.houses', string='Depo Adı: ')
@api.depends('quantity', 'price')
def _unitPriceCalcuteFunc(self):
for record in self:
record.unit_price = record.price * record.quantity
def action_delete(self):
vals = {
'ref_code': self.ref_code,
'product_name': self.product_name,
'product_description': self.product_description,
'teslim_alan': self.teslim_alan,
'teslim_eden': self.teslim_eden,
'quantity': self.quantity,
'price': self.price,
'unit_price': self.unit_price,
'warehouse_id': self.warehouse_id
}
self.env['scrap'].create(vals)
return super(InventoryMenu, self).unlink()

这是我的废料模块:

class Scrap(models.Model):
_name = "scrap"
_description = "Scrap"
ref_code = fields.Char(string="Referans Numarası: ", required=True, tracking=True, default="000000")
product_name = fields.Char(string="Ürün Adı: ", required=True, tracking=True, )
product_description = fields.Char(string="Ürün Tanımı: ", required=True, tracking=True, )
teslim_alan = fields.Char(string="Teslim Alan: ", required=True, tracking=True, )
teslim_eden = fields.Char(string="Teslim Eden: ", required=True, tracking=True, )
quantity = fields.Float(string="Miktar: ", required=True, tracking=True, )
price = fields.Float(string="Fiyat: ", required=True, tracking=True, )
unit_price = fields.Float(string="Birim Fiyat: ", compute="_unitPriceCalcuteFunc")
warehouse_id = fields.Many2one('ware.houses', string='Depo Adı: ')
@api.depends('quantity', 'price')
def _unitPriceCalcuteFunc(self):
for record in self:
record.unit_price = record.price * record.quantity
def action_getback(self):
vals = {
'ref_code': self.ref_code,
'product_name': self.product_name,
'product_description': self.product_description,
'teslim_alan': self.teslim_alan,
'teslim_eden': self.teslim_eden,
'quantity': self.quantity,
'price': self.price,
'unit_price': self.unit_price,
'warehouse_id': self.warehouse_id
}
self.env['inventory.menu'].create(vals)
return super(Scrap, self).unlink()

以下是上述代码的解决方案:

'warehouse_id': self.warehouse_id

请将此行更改为:

'warehouse_id': self.warehouse_id.id

action_deleteaction_getback方法中创建val时。

根本原因:当您传递要在模型中创建的值字典时,请确保每个字段都有正确的值。

对于EX:如果字段为Many2one,则需要传递record_id(type=int),因为odoo将直接将id浏览到相关模型,并将记录放置到该字段。

相关内容

  • 没有找到相关文章

最新更新