You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Odoo 16:如何根据产品SN将stock.lot的attributes字段添加至POS订单行

实现POS订单行展示序列号的attributes字段

1. 后端数据配置

  • 确保stock.lot的attributes字段已被纳入POS的数据加载范围,扩展POS会话的加载参数:
    from odoo import models
    
    class PosSession(models.Model):
        _inherit = 'pos.session'
    
        def _loader_params_stock_lot(self):
            result = super()._loader_params_stock_lot()
            # 将attributes字段加入POS加载的lot字段列表
            result['search_params']['fields'].append('attributes')
            return result
    
  • 若需要在POS订单行中持久化存储该属性,可扩展pos.order.line模型:
    from odoo import models, fields
    
    class PosOrderLine(models.Model):
        _inherit = 'pos.order.line'
    
        lot_attributes = fields.Text(string="序列号属性", related='lot_id.attributes', store=True)
    

2. 前端POS界面修改

  • 找到POS订单行的模板文件(通常在point_of_sale/static/src/xml/pos.xml或自定义模块的XML文件中),通过继承模板添加属性展示:
    <t t-name="CustomOrderline" t-inherit="point_of_sale.Orderline" t-inherit-mode="primary">
        <xpath expr="//div[@class='product-name']" position="after">
            <div class="lot-attributes" t-if="line.lot_id">
                <t t-esc="line.lot_id.attributes"/>
            </div>
        </xpath>
    </t>
    

3. 样式优化(可选)

  • 在自定义模块的CSS文件中添加样式,优化属性显示效果:
    .lot-attributes {
        font-size: 0.85em;
        color: #555;
        margin-top: 3px;
        font-style: italic;
    }
    

4. 验证测试

  • 升级自定义模块,重启Odoo服务,清除浏览器缓存后打开POS界面,选择带有序列号的产品,检查订单行是否正常显示attributes字段内容。

内容的提问来源于stack exchange,提问作者Emad

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.27 03:54:58