Odoo 10 - 给定 product_template 的重复供应商信息
Odoo 10 - Duplicate supplier info for a given product_template
我有:
- a) 给定 product_template_id(即 id 100)和
- b) 使用 copy() 方法创建的重复 product_template_id(即 id 200)
copy() 方法仅复制 product.template 模型,因此不会复制该特定产品的供应商。
我想复制该模型的所有供应商,但现在我想知道在 Odoo 中哪种方法正确。
如果我正确理解模型,给定产品的供应商价格存储在 product_supplierinfo table 中,其中指向给定 product_tmpl_id 的每条记录都指定供应商 price/qty 对于给定的 product_template.
这将是 Odoo 中搜索指向给定 product_tmpl_id(即 100)的所有记录的方式,复制它们并将 product_tmpl_id 更改为新记录(即 200)?
copy (bool
) -- whether the field value should be copied when the record is duplicated (default: True
for normal fields, False
for One2many
and computed fields, including property fields and related fields)
您所指的字段是seller_ids
,其字段定义如下:
seller_ids = fields.One2many('product.supplierinfo', 'product_tmpl_id', 'Vendors')
copy
属性未明确定义,因此默认为 False
(如上述文档中所述)。如果你想在标准产品"Duplicate"(copy
方法)期间将此字段与其他值一起复制,你可以这样做:
class ProductTemplate(models.Model):
_inherit = 'product.template'
# This only changes the copy attribute of the existing seller_ids field.
# All other attributes (string, comodel_name, etc.) remain as they are defined in core.
seller_ids = fields.One2many(copy=True)
或者
如果有时只想复制字段,可以扩展 copy
方法以查找特定的上下文值并仅基于该值进行复制。
# This may take some tweaking, but here's the general idea
@api.multi
def copy(self, vals):
new_product = super(YourClass, self).copy(vals)
if vals.get('copy_sellers'):
new_product.seller_ids = self.seller_ids.copy({'product_id': new_product.id})
return new_product
# Whatever you have calling the copy method will need to include copy_sellers in vals
vals.update({'copy_sellers': True})
product.copy(vals)
我有:
- a) 给定 product_template_id(即 id 100)和
- b) 使用 copy() 方法创建的重复 product_template_id(即 id 200)
copy() 方法仅复制 product.template 模型,因此不会复制该特定产品的供应商。
我想复制该模型的所有供应商,但现在我想知道在 Odoo 中哪种方法正确。
如果我正确理解模型,给定产品的供应商价格存储在 product_supplierinfo table 中,其中指向给定 product_tmpl_id 的每条记录都指定供应商 price/qty 对于给定的 product_template.
这将是 Odoo 中搜索指向给定 product_tmpl_id(即 100)的所有记录的方式,复制它们并将 product_tmpl_id 更改为新记录(即 200)?
copy (
bool
) -- whether the field value should be copied when the record is duplicated (default:True
for normal fields,False
forOne2many
and computed fields, including property fields and related fields)
您所指的字段是seller_ids
,其字段定义如下:
seller_ids = fields.One2many('product.supplierinfo', 'product_tmpl_id', 'Vendors')
copy
属性未明确定义,因此默认为 False
(如上述文档中所述)。如果你想在标准产品"Duplicate"(copy
方法)期间将此字段与其他值一起复制,你可以这样做:
class ProductTemplate(models.Model):
_inherit = 'product.template'
# This only changes the copy attribute of the existing seller_ids field.
# All other attributes (string, comodel_name, etc.) remain as they are defined in core.
seller_ids = fields.One2many(copy=True)
或者
如果有时只想复制字段,可以扩展 copy
方法以查找特定的上下文值并仅基于该值进行复制。
# This may take some tweaking, but here's the general idea
@api.multi
def copy(self, vals):
new_product = super(YourClass, self).copy(vals)
if vals.get('copy_sellers'):
new_product.seller_ids = self.seller_ids.copy({'product_id': new_product.id})
return new_product
# Whatever you have calling the copy method will need to include copy_sellers in vals
vals.update({'copy_sellers': True})
product.copy(vals)