跳至内容
Odoo 菜单
  • 登录
  • 免费试用
  • 应用程序
    财务
    • 会计
    • 发票
    • 费用
    • 电子表格 (BI)
    • 文档
    • 电子签名
    销售
    • 客户关系管理
    • 销售
    • POS 销售点管理-零售
    • POS 销售点管理 - 餐厅
    • 订阅
    • 租赁
    网站
    • 网站设计
    • 电子商务
    • 博客
    • 论坛
    • 在线客服
    • 在线学习
    供应链
    • 库存
    • 制造
    • 产品生命周期
    • 采购
    • 维护保养
    • 品控
    人力资源
    • 员工
    • 招聘
    • 休假
    • 评价
    • 内部推荐
    • 车队
    营销
    • 社媒营销
    • 电邮营销
    • 短信营销
    • 近期活动
    • 营销自动化
    • 网上调查
    服务
    • 项目管理
    • 工时单
    • 现场服务
    • 服务台
    • 排期
    • 预约
    生产力
    • 讨论
    • 批核
    • IoT物联网
    • VoIP
    • 知识库
    • WhatsApp
    第三方应用软件 Odoo 定制 Odoo云端平台
  • 行业
    零售
    • 书店
    • 服装店
    • 家具店
    • 食品杂货店
    • 五金店
    • 玩具店
    餐饮与酒店服务
    • 酒吧及酒馆
    • 餐厅
    • 快餐
    • 民宿
    • 饮品分销商
    • 酒店
    房地产
    • 房地产代理
    • 建筑师事务所
    • 建造业
    • 地产管理
    • 园艺
    • 业主协会
    咨询
    • 会计师事务所
    • Odoo合作伙伴
    • 市场推广公司
    • 律师事务所
    • 人才招聘
    • 审核 & 认证
    制造
    • 纺织
    • 金属
    • 家具
    • 食品
    • 啤酒厂
    • 企业礼品
    保健与健身
    • 体育俱乐部
    • 眼镜店
    • 健身中心
    • 健康从业者
    • 药房
    • 发型屋
    Trades
    • 维修人员
    • IT 硬件及支持
    • 太阳能系统
    • 鞋匠
    • 清洁服务
    • 暖通空调服务
    其他
    • 非营利组织
    • 环境机构
    • 广告牌租赁
    • 摄影服务
    • 自行车租赁
    • 软件经销商
    浏览所有行业
  • 社区
    学习
    • 教学视频
    • 文档
    • 认证
    • 培训
    • 博客
    • 播客
    赋能教育
    • 教育计划
    • Scale Up! 商业游戏
    • 参观Odoo
    获取软件
    • 下载
    • 版本对比
    • 发布
    合作
    • Github
    • 论坛
    • 近期活动
    • 翻译
    • 成为合作伙伴
    • 合作伙伴服务
    • 注册您的会计事务所
    获取服务
    • 寻找合作伙伴
    • 查找会计服务
    • 预约顾问咨询
    • 安装及推行服务
    • 客户参考
    • 支持
    • 升级
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    获取演示
  • 定价
  • 技术支持

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • 客户关系管理
  • e-Commerce
  • 会计
  • 库存
  • PoS
  • 项目
  • MRP
All apps
只限注册用戶才可与社群互动。
所有帖文 人 徽章
标签 (查看所有)
odoo accounting v14 pos v15
关于此论坛区
只限注册用戶才可与社群互动。
所有帖文 人 徽章
标签 (查看所有)
odoo accounting v14 pos v15
关于此论坛区
帮助

Merge Product Attribute Values. Please Help

订阅

此帖文有活动时,接收通知

此问题已终结
valuesmergeattributesattributevalue
2 回复
2844 查看
形象
SEA International Co.,Ltd.

Hi,

I recently started using odoo.sh V.15 ent. While new to the software I made some errors and duplication.

I would like to know if there is a way to Merge Attribute 'VALUES'? For example we created attribute value under Attribute 'Size' as Large, LARGE, LArge1, L,  which all mean the same thing. How do I merge these attributes as 1 and delete the rest?


 I know we can archive the values, but I would have to go through all the list of variants with outstanding stock and create new variants for them and input stock amount. This will take a lot of time.


Please help.

0
形象
丢弃
形象
Luis San Segundo
最佳答案

Odoo does not provide any "easy or standard" way of doing this.

I would do a "server action" 

Give the action a list of Attribute 'VALUES' to be merged. And a variable containing the "new" Attribute 'VALUE'.

Then go over product.product and check if ANY of the attribute values correspond with the ones on your list.

And if so, then Add the new value to the product.product, and remove the old ones from that product.product.


Also you should take into account the stock.moves, quants, etc of the duplicated product.product


So the final result should be just one product.product variant.

I used AI to generate a code that could make this

!!!WARNING!!!: i have not tested this code, please use it as reference, and test it un demo database before trying in production.


The goal is to merge redundant attribute values (such as "Large," "LARGE," etc.) into one unified value under the same product attribute in Odoo 17. This needs to be done efficiently across all products and their variants without disrupting stock or creating new variants manually.


Problem Breakdown:

Redundant Attribute Values: You have multiple variants of the "Size" attribute that all represent the same meaning (e.g., "Large", "LARGE", etc.).

Merging Requirement: The goal is to identify products with these redundant values, replace them with a unified value, and delete or archive the old ones.


Current Constraints:

Odoo does not have a standard feature to merge attribute values.

Manually updating variants and stock would be time-consuming.

Steps to Solve the Problem:

Server Action: Using a server action can automate this process.

The server action will:

Take a list of old values (e.g., "Large", "LARGE", etc.).

Identify products/variants that use these values.

Replace the old values with a unified one (e.g., "Large").

Archive or delete the old values.


Considerations:

Stock Handling: Odoo tracks stock per product variant. When changing attribute values, Odoo could potentially treat it as a new product variant. Therefore, ensuring the stock is carried over correctly is crucial.

Product Variants: Product variants with these attribute values must be updated without creating new ones, as this would lead to stock management issues.

Data Integrity: Care must be taken to ensure that relationships between products, attributes, and stock are preserved.


Alternative Approach:

Instead of merging in bulk, manually adjusting stock might be the safest route, but this is not feasible for a large volume of data. A custom migration script or server action is the most efficient way, as Odoo doesn't offer this feature natively.


Final Approach:

Loop through the product.product model to identify products with the redundant attribute values.

Replace these values with the unified value.

Ensure that the product variant remains the same, avoiding new variant creation.

Archive the old attribute values after the process.


Explanation:

The script begins by locating the attribute ("Size") and the relevant attribute values that need to be merged.

It loops through the products (product.product) that contain the old attribute values and updates them with the new unified value.

After updating the products, it archives the old values so they are no longer in use but can be referred back to if needed.

The function is parameterized so it can be reused for other attributes as well.


The request to merge redundant attribute values while ensuring that only one product.product remains requires a deeper reflection on Odoo's stock and order management systems. Changing or merging product attributes can affect various models such as stock.move, stock.move.line, stock.quant, sale.order.line, purchase.order.line, and possibly mrp.production (if manufacturing is involved). Handling these relations properly will ensure that no stock discrepancies, broken references, or invalid product variants occur.


Problem Breakdown:

Primary Objective: Merge attribute values so that only one product.product variant remains, without creating new variants.


Stocks and Orders: Odoo tracks product movements through multiple models such as stock.quant (for current stock quantities), stock.move (for ongoing product movements), sale.order.line (for product sales), purchase.order.line (for product purchases), etc. Any product with stock or movement cannot simply be deleted without proper handling.


Possible Issues:

Deleting a product.product that has stock or is linked to any ongoing orders could result in data integrity issues.

Orders, deliveries, and manufacturing processes might still reference old variants, leading to broken references if not handled carefully.

Goal: Transfer all relevant data from old product variants (with redundant attribute values) to a unified product variant, updating references and consolidating stock, before safely removing redundant variants.


Steps to Address the Problem:

Stock Consolidation: Ensure all stock for old variants is transferred to the new product variant.

Check and update stock.quant for current stock levels.

Update stock.move and stock.move.line for ongoing stock transfers or deliveries.


Order and Transaction Handling:

Update sale.order.line, purchase.order.line, and any other transaction records that reference the old product variants to point to the new one.

Data Integrity: Ensure that no dangling references to the old product variants remain in any models after the merge.

Archive Old Variants: After successfully transferring stock and updating all references, old product variants should be archived, but not deleted, for traceability.


Considerations:

Stock Levels: Ensure that stock is accurately transferred. Use the stock.quant model for this.

Ongoing Orders: Any ongoing orders or transfers should be properly adjusted by updating their product_id to the new variant.

Atomic Operation: The process should be done in an atomic way to prevent issues if the process is interrupted.


Alternative Approaches:

One alternative approach could be to handle this manually via export/import tools or scripts outside of Odoo, but this would still be inefficient and prone to errors. A properly scripted server action or module is the most efficient solution given the complexity and scale of the task.


Final Approach:

The script should:


  • Identify all models that reference the product.product variants (including stock and orders).
  • Update all these references to the new product variant.
  • Transfer stock from old variants to the new one.
  • Archive the old variants to avoid conflicts.

 

# python code


def merge_product_variants(attribute_name, old_values, new_value):

    # Get the attribute by name

    attribute = env['product.attribute'].search([('name', '=', attribute_name)], limit=1)

    if not attribute:

        raise ValueError(f"Attribute '{attribute_name}' not found.")

   

    # Get the new unified attribute value

    new_attribute_value = env['product.attribute.value'].search([('attribute_id', '=', attribute.id), ('name', '=', new_value)], limit=1)

    if not new_attribute_value:

        raise ValueError(f"New Attribute Value '{new_value}' not found.")

   

    # Get old attribute values to be merged

    old_attribute_values = env['product.attribute.value'].search([('attribute_id', '=', attribute.id), ('name', 'in', old_values)])

   

    if not old_attribute_values:

        raise ValueError(f"No old attribute values found for {old_values}.")

   

    # Find all products using old attribute values

    old_products = env['product.product'].search([('attribute_value_ids', 'in', old_attribute_values.ids)])

   

    # Find or create the new product variant that should remain

    new_product = env['product.product'].search([('attribute_value_ids', 'in', new_attribute_value.ids)], limit=1)

    if not new_product:

        raise ValueError(f"Product with the new value '{new_value}' not found.")

   

    # Migrate stock from old products to the new one

    for old_product in old_products:

        if old_product != new_product:

            # Transfer stock.quants

            quants = env['stock.quant'].search([('product_id', '=', old_product.id)])

            for quant in quants:

                quant.sudo().write({'product_id': new_product.id})

           

            # Transfer stock.move.lines

            move_lines = env['stock.move.line'].search([('product_id', '=', old_product.id)])

            for line in move_lines:

                line.sudo().write({'product_id': new_product.id})

           

            # Transfer stock.moves

            moves = env['stock.move'].search([('product_id', '=', old_product.id)])

            for move in moves:

                move.sudo().write({'product_id': new_product.id})

           

            # Transfer ongoing orders (sale.order.line, purchase.order.line)

            sale_order_lines = env['sale.order.line'].search([('product_id', '=', old_product.id)])

            for sol in sale_order_lines:

                sol.sudo().write({'product_id': new_product.id})

           

            purchase_order_lines = env['purchase.order.line'].search([('product_id', '=', old_product.id)])

            for pol in purchase_order_lines:

                pol.sudo().write({'product_id': new_product.id})

   

            # Archive the old product variant

            old_product.sudo().write({'active': False})

   

    return f"Successfully merged products with values {old_values} into '{new_value}', stock and orders transferred."


# Parameters for merging

merge_product_variants(

    attribute_name='Size',  # The attribute name

    old_values=['Large', 'LARGE', 'LArge1', 'L'],  # Old attribute values

    new_value='Large'  # New unified value

)


Explanation:

Finding the Products: The script first searches for the old product variants that need to be merged.

Stock Transfer: It loops through stock.quant, stock.move, and stock.move.line records related to each old product and updates them to point to the new product.

Order Transfer: It handles ongoing orders by updating sale.order.line and purchase.order.line records to point to the new product.

Archiving Old Variants: After stock and orders are transferred, the old products are archived to ensure only one product remains active.

This method ensures that stock, orders, and all relevant transactions are updated seamlessly to reflect the unified product, preventing any disruptions in stock management or orders.

0
形象
丢弃
形象
Umar Abdul Muntaqin
最佳答案

i think it's posible with Large, LARGE, LArge1,
but if L or L4rg3, it's not posible

you can use python .find() to do that, but you of to make lowercase first using .lower()

0
形象
丢弃
喜欢讨论吗?不要只阅读,加入进来!

立即创建账户,享受专属功能,与我们的精彩社区互动!

注册
相关帖文 回复 查看 活动
How to change attribute values order/sequence when over 40 values? 已解决
values products attributes
形象
形象
形象
3
7月 24
3079
How to change specific attribute values and add new attributes to existing product variants.
values attributes Exporting importing data from excel file
形象
0
2月 25
3718
Odoo V18 Import Issue: Product Variants with Attributes Causing Errors
product values variants attributes
形象
形象
2
1月 25
2411
Import attribute values in V16 已解决
import values attributes odoo16features
形象
形象
2
10月 23
5075
Conditional Attributes value for particular product variants (V13) 已解决
values variants attributes v13
形象
形象
4
9月 21
6794
社区
  • 教学视频
  • 文档
  • 论坛
开源
  • 下载
  • Github
  • Runbot
  • 翻译
服务
  • Odoo.sh 托管
  • 支持
  • 升级
  • 自定义开发服务
  • 教育
  • 查找会计服务
  • 寻找合作伙伴
  • 成为合作伙伴
关于我们
  • 我们的公司
  • 品牌资产
  • 联系我们
  • 招聘
  • 近期活动
  • 播客
  • 博客
  • 客户
  • 法律 • 隐私
  • 安全
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo致力于为企业管理提供高效智能的开源解决方案,是全球业内高速成长的软件服务商之一,逾七百五十万用户选择Odoo进行数字化升级。通过一系列全业务链覆盖、高度集成、简单易用的商业应用,助力企业实现信息化改革、降本增效并释放公司增长潜力。

Odoo独特的价值在于是一款非常容易使用又完全集成的应用。

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now