Python 重复记录丢失多个字段问题
我的产品带有来自自定义模块的额外字段。我正试图重写copy函数,因为当我尝试复制产品时,有些值不会复制 因此,在这个复制函数中,我设法添加了这些字段,但如果我尝试只添加原始产品字段中的ID,那么在复制产品后,该字段将丢失这些值。我想这是有道理的 代码:Python 重复记录丢失多个字段问题,python,openerp,odoo-10,odoo-11,Python,Openerp,Odoo 10,Odoo 11,我的产品带有来自自定义模块的额外字段。我正试图重写copy函数,因为当我尝试复制产品时,有些值不会复制 因此,在这个复制函数中,我设法添加了这些字段,但如果我尝试只添加原始产品字段中的ID,那么在复制产品后,该字段将丢失这些值。我想这是有道理的 代码: class ProductTemplate(models.Model): _inherit= 'product.template' @api.multi def copy(self, default=None):
class ProductTemplate(models.Model):
_inherit= 'product.template'
@api.multi
def copy(self, default=None):
default = dict(default or {})
array_attribute_line_ids = []
for value_id in self.attribute_line_ids.read([]):
array_attribute_line_ids += [(4,value_id['id'])]
print (array_attribute_line_ids)
default.update({
# General Information
# 'standard_price': self.standard_price,
# Variants > Attributes
'attribute_line_ids': array_attribute_line_ids,
# Purchase > Vendors
# Inventory
'weight': self.weight,
'volume': self.volume,
# Invoicing
'property_account_income_id': self.property_account_income_id,
'supplier_taxes_id': self.supplier_taxes_id, #NOT WORKING
'property_account_expense_id': self.property_account_expense_id,
'property_account_creditor_price_difference': self.property_account_creditor_price_difference,
})
return super(ProductTemplate, self).copy(default)
查看:当前字段是显示在图像底部的属性线ID
问题:我可以在原始记录的基础上创建新记录,但问题是其中一个值取决于许多需要值“product\u tmpl\u id”的记录,该值是产品的id。因此,如果我还没有新产品的id,因为它目前还没有被复制,那么我如何创造这些价值呢
以前,我在另一个功能中创建了记录,然后使用其id更新这些值。现在不可能了
有办法解决这个问题吗?是否有一个.copy()函数允许我复制所有这些记录,而无需手动创建
非常感谢你
这是odoo 11 enterprise。IIUC您希望在复制产品时复制产品属性。我相信您可以通过将
product.template
attributecopy
上的字段attribute\u line\u id
更改为True
来实现这一点:
来自odoo导入字段、模型的
类ProductTemplate(models.Model):
_inherit='product.template'
attribute_line_id=fields.One2many(copy=True)
我试过这个,但没用。有什么建议吗?我仍然有相同的行为。您是否正在更改default
dict inproduct.template
copy
方法中属性行ID
的值?因为您不需要使用我描述的解决方案来实现这一点。我已经在本地测试了它,它对我很有效(当产品被复制时,产品属性被复制)。是的,你是对的。现在可以了。我真的很感谢你的帮助。这让我头疼。