跳转到主要内容

用于在一对多字段中选择产品的小部件

项目描述

Beta License: AGPL-3 OCA/web Translate me on Weblate Try me on Runbot

为创建与product.product记录相关联的一对多行添加了“one2many_product_picker”友好的移动小部件。

目录

安装

建议安装‘web_widget_numeric_step’以在触摸屏上获得更好的可用性。

配置

创建或编辑一个新的视图,并使用名为“one2many_product_picker”的新小部件。您需要定义视图字段。视图必须是form类型。

小部件选项

  • groups > 字典数组 -> 声明组

    • name -> 组名

    • string -> 显示的文本

    • domain -> 强制使用的域

    • order -> 排序

      • name -> 排序的字段名

      • asc -> 使用“asc”排序的标志

    • records_per_page > 整数 -> 用于控制加载更多行为(默认为16)

    • active -> 布尔值 -> 选择默认要使用的组(默认为“false” = “All”组)

  • currency_field > 用于格式化货币值的模型字段(默认为“currency_id”)

  • field_map > 字典

    • product -> 表示产品的字段(默认为product_id

    • name -> 表示名称的字段(默认为“name”)

    • product_uom -> 表示产品单位字段(默认为‘product_uom’)

    • product_uom_qty -> 表示产品单位数量字段(默认为‘product_uom_qty’)

    • price_unit -> 表示价格单位字段(默认为‘price_unit’)

    • discount -> 表示折扣字段(默认为‘discount’)

  • search -> 字典数组(默认使用name_search)

    • name -> 显示名称

    • domain -> 使用的域

      • $search -> 替换为搜索框的当前值

      • $number_search -> 将所有叶子节点替换为搜索框的当前值作为数字

    • name_search_value -> 启用使用‘name_search’代替‘search_read’,并定义要搜索的值(默认为‘$search’)

    • operator -> 在‘name_search’中使用的运算符(默认为‘ilike’)

  • edit_discount -> 启用/禁用折扣编辑(默认为False)

  • edit_price -> 启用/禁用价格编辑(默认为True)

  • show_discount -> 启用/禁用显示折扣(默认为False)

  • show_subtotal -> 启用/禁用显示小计(默认为True)

  • auto_save -> 启用/禁用自动保存(默认为False)

  • auto_save_delay -> 在启动自动保存之前等待最后交互的时间(以毫秒为单位)(默认为1500)

  • all_domain -> 在‘全部’部分使用的域(默认为[])

    如果使用自动保存功能,请注意,“保存”和“丢弃”按钮将失去部分功能,因为每次使用小部件修改/创建记录时,文档都会被保存。

  • ignore_warning -> 启用/禁用显示onchange警告(默认为False)

  • instant_search -> 启用/禁用即时搜索模式(默认为False)

  • trigger_refresh_fields -> 主记录中触发小部件刷新的字段(默认为[“partner_id”, “currency_id”])

  • auto_focus -> 在执行搜索后保持搜索框的焦点(默认为True)

所有小部件选项都是可选的。请注意,您可以使用‘_’方法来使用翻译。这只能与该小部件一起使用。

示例

options="{'search': [{'name': _('Starts With'), 'domain': [('name', '=like', '$search%')]}], 'groups': [{'name': 'cheap', 'string': _('Cheap'), 'domain': [('list_price', '<', 10.0)], 'field_map': { 'product': 'my_product_id' }}]}"

默认上下文

小部件发送一个默认的上下文与‘search_read’请求

  • active_search_group_name -> 包含活动搜索组的名称

    • ‘all’ -> 是‘全部’组的硬编码名称

    • ‘main_lines’ -> 是‘行’组的硬编码名称

  • active_search_involved_fields -> 包含一个包含用于搜索框内容的字段的字典数组

    • ‘type’ -> 可以是‘text’或‘number’

    • ‘field’ -> 字段名称

    • ‘oper’ -> 使用的运算符

示例

这是一个使用‘sale.order.line’字段的示例

<field
    name="order_line"
    attrs="{'readonly': [('state', 'in', ('done','cancel'))]}"
    nolabel="1"
    mode="form"
    widget="one2many_product_picker"
    options="{'search': [{'name': 'Test', 'domain': [['name', 'ilike', '$search']]}] ,'edit_discount': True, 'show_discount': True, 'groups': [{'name': 'desk', 'string': _('Desks'), 'domain': [('name', 'ilike', '%desk%')], 'order': [{'name': 'id', 'asc': true}]}, {'name': 'chair', 'string': _('Chairs'), 'domain': [('name', 'ilike', '%chair%')]}]}"
>
    <form>
        <field name="state" invisible="1" />
        <field name="display_type" invisible="1" />
        <field name="currency_id" invisible="1" />
        <field name="discount" widget="numeric_step" options="{'max': 100}" invisible="1"/>
        <field name="price_unit" widget="numeric_step" invisible="1"/>
        <field name="name" invisible="1" />
        <field name="product_id" invisible="1" />
        <field name="order_id" invisible="1"/>
        <field name="product_uom_qty" class="mb-1" widget="numeric_step" context="{
            'partner_id': parent.partner_id,
            'quantity': product_uom_qty,
            'pricelist': parent.pricelist_id,
            'uom': product_uom,
            'company_id': parent.company_id
        }" />
        <field name="product_uom" force_save="1" attrs="{
            'readonly': [('state', 'in', ('sale','done', 'cancel'))],
            'required': [('display_type', '=', False)],
        }" context="{'company_id': parent.company_id}" class="mb-2" options="{'no_open': True, 'no_create': True, 'no_edit': True}" />
    </form>
</field>

** 在此示例中,我们没有使用‘field_map’选项,因为默认匹配sale.order.line字段名称。

对于‘purchase.order.line’字段的另一个示例

<field
    name="order_line"
    attrs="{'readonly': [('state', 'in', ('done','cancel'))]}"
    nolabel="1"
    widget="one2many_product_picker"
    mode="form"
    options="{'search': [{'name': _('Name'), 'domain': [['name', 'ilike', '$search']]}, {'name': _('Price'), 'domain': [['list_price', '=', $number_search]]}], 'field_map': {'product_uom_qty': 'product_qty'}, 'groups': [{'name': _('Desk'), 'domain': [['name', 'ilike', 'desk']], 'order': {'name': 'id', 'asc': true}}, {'name': _('Chairs'), 'domain': [['name', 'ilike', 'chair']]}]}"
>
    <form>
        <field name="name" invisible="1" />
        <field name="product_id" invisible="1" />
        <field name="price_unit" invisible="1"  />
        <field name="currency_id" invisible="1" />
        <field name="order_id" invisible="1" />
        <field name="date_planned" class="mb-1" />
        <field name="product_qty" class="mb-1" widget="numeric_step" required="1" />
        <field name="product_uom" class="mb-2" options="{'no_open': True, 'no_create': True, 'no_edit': True}" />
    </form>
</field>

Boostrap修改

产品选择器视图容器有一个自定义的媒体查询空间,添加了一个新的屏幕大小‘xxl’(>= 1440px),并将列数修改为24而不是12。这意味着您可以在产品选择器视图容器中使用“col-xxl-”。

用法

当您更改字段的值并切换到编辑另一条记录时,更改将应用到先前的记录,而无需单击接受更改。

小部件部分

https://raw.githubusercontent.com/OCA/web/13.0/web_widget_one2many_product_picker/static/img/product_picker_anat.png

预览

https://raw.githubusercontent.com/OCA/web/13.0/web_widget_one2many_product_picker/static/img/product_picker.gif

已知问题/路线图

  • 在字段使用小部件的xml ‘options’属性中的翻译无法自动导出以进行翻译

  • 产品卡片动画可以改进。目前卡片被重新创建,所以我们失去了应用正确效果的一些元素

  • 影响“order_line”子字段的sale.order onchanges将被省略以提高性能

错误追踪器

错误追踪在GitHub Issues上。如果在那里遇到麻烦,请检查您的问题是否已被报告。如果您是第一个发现它的人,请帮助我们消除它,提供详细且受欢迎的反馈

请不要直接联系贡献者询问支持或技术问题。

致谢

作者

  • 技术那达

贡献者

维护者

此模块由OCA维护。

Odoo Community Association

OCA,或Odoo社区协会,是一个非营利组织,其使命是支持Odoo功能的协作开发并推广其广泛使用。

此模块是GitHub上的OCA/web项目的一部分。

欢迎您贡献。要了解如何进行贡献,请访问https://odoo-community.org/page/Contribute

项目详情


下载文件

下载您平台上的文件。如果您不确定选择哪个,请了解更多关于安装包的信息。

源代码分发

此版本没有可用的源代码分发文件。有关生成分发存档的教程,请参阅生成分发存档

构建分发

支持者