产品字段筛选、拼接

This commit is contained in:
李鹏宇
2026-02-25 19:45:21 +08:00
parent aa3b4bc231
commit 6b5533949a
4 changed files with 56 additions and 5 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
# -*- coding: utf-8 -*-
from . import inherit_stock_picking
from . import Inherit_stock_picking_type
from . import inherit_stock_location
from . import inherit_stock_location
from . import inherit_stock_move
+24
View File
@@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from odoo import models, fields, api
class ProductProduct(models.Model):
_inherit = 'product.product'
display_name = fields.Char(
string="Display Name",
compute='_compute_display_name',
store=False
)
@api.depends('name', 'qty_available')
def _compute_display_name(self):
"""计算产品显示名称,包含在手数量"""
for record in self:
name = record.name or ""
qty_available = record.qty_available
record.display_name = f"{name} (在手: {qty_available:.2f})"
class StockMove(models.Model):
_inherit = 'stock.move'
+19 -1
View File
@@ -28,7 +28,7 @@ class StockPicking(models.Model):
('acceptance', '验收'),
('certification', '证明'),
('receipt', '入库')
], string="入库单状态", default='receipt')
], string="入库单状态", default='acceptance')
acceptance_date = fields.Datetime(string="验收时间", readonly=True)
certification_date = fields.Datetime(string="证明时间", readonly=True)
json_display = fields.Char(
@@ -36,6 +36,24 @@ class StockPicking(models.Model):
compute='_compute_json_display',
store=True
)
available_product_ids = fields.Many2many(
'product.product',
compute='_compute_available_product_ids',
string="可用产品"
)
@api.depends('location_id')
def _compute_available_product_ids(self):
"""根据仓库计算可用产品列表"""
for record in self:
if record.location_id:
# 查询该仓库中有库存的产品
quants = self.env['stock.quant'].search([
('location_id', '=', record.location_id.id)
])
record.available_product_ids = quants.mapped('product_id')
else:
record.available_product_ids = False
@api.onchange('user_id')
def _onchange_user_id(self):
+11 -3
View File
@@ -9,11 +9,14 @@
<field name="department_id" options="{'no_create': True}"/>
</xpath>
<xpath expr="//field[@name='origin']" position="after">
<field name="receipt_status"/>
<field name="receipt_status" invisible="1"/>
<field name="user_id" string="采购人员"/>
<field name="available_product_ids" invisible="1"/>
<field name="state" invisible="1"/>
</xpath>
<xpath expr="//page[@name='operations']//field[@name='move_ids_without_package']//field[@name='product_id']" position="attributes">
<attribute name="options">{'no_create': True}</attribute>
<attribute name="domain">[('id', 'in', parent.available_product_ids)]</attribute>
</xpath>
<xpath expr="//header/button[@name='%(stock.act_stock_return_picking)d']" position="after">
<button name="action_acceptance" string="验收" type="object" class="btn-primary" invisible="receipt_status != 'acceptance'"/>
@@ -37,9 +40,11 @@
</xpath>
<xpath expr="//button[@name='button_validate' and @class='oe_highlight']" position="attributes">
<attribute name="string">证明</attribute>
<attribute name="invisible">receipt_status != 'certification'</attribute>
</xpath>
<xpath expr="//button[@name='button_validate' and @class='o_btn_validate']" position="attributes">
<attribute name="string">证明</attribute>
<attribute name="invisible">receipt_status != 'certification'</attribute>
</xpath>
<xpath expr="//field[@name='picking_properties']" position="attributes">
<attribute name="invisible">1</attribute>
@@ -56,8 +61,11 @@
<xpath expr="//field[@name='partner_id']" position="attributes">
<attribute name="string">供应商</attribute>
</xpath>
<xpath expr="//field[@name='state' and @widget='statusbar' and @invisible]" position="replace">
<field name="receipt_status" widget="statusbar" statusbar_visible="acceptance,certification,receipt"/>
<xpath expr="(//field[@name='state'][@widget='statusbar'])[1]" position="replace">
<field name="receipt_status" widget="statusbar" statusbar_visible="acceptance,certification,receipt" invisible="picking_type_code != 'incoming'"/>
</xpath>
<xpath expr="(//field[@name='state'][@widget='statusbar'])[1]" position="replace">
<field name="receipt_status" widget="statusbar" statusbar_visible="acceptance,certification,receipt" invisible="picking_type_code == 'incoming'"/>
</xpath>
</field>
</record>