跳转到主要内容

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

项目描述

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

添加了名为‘one2many_product_picker’的友好移动小部件,用于创建与product.product记录相关联的一对多行。

目录

安装

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

配置

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

小部件选项

  • 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’)

    • product_uom_qty -> 代表product_uom_qty的字段(默认为‘product_uom_qty’)

    • price_unit -> 代表price_unit的字段(默认为‘price_unit’)

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

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

    • 名称 -> 要显示的名称

    • 域 -> 要使用的域

      • $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 -> 启用/禁用显示更改时的警告(默认为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/12.0/web_widget_one2many_product_picker/static/img/product_picker_anat.png

预览

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

已知问题/路线图

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

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

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

错误跟踪器

错误在GitHub Issues上跟踪。如果在有问题的情况下,请检查您的错误是否已被报告。如果您是第一个发现它的人,请通过提供详细和欢迎的反馈来帮助我们消除它。

请勿直接联系贡献者以获取支持或技术问题的帮助。

致谢

作者

  • Tecnativa

贡献者

维护者

此模块由OCA维护。

Odoo Community Association

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

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

欢迎您贡献力量。有关如何贡献的信息,请访问https://odoo-community.org/page/Contribute

项目详情


下载文件

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

源代码分布

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

构建分布

由以下组织支持

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页面