优化库存排序

This commit is contained in:
guanhuan
2025-04-17 13:44:25 +08:00
parent 06e9d5a538
commit 9cfc8418ec
7 changed files with 62 additions and 12 deletions

View File

@@ -19,7 +19,6 @@ from odoo.addons.sf_mrs_connect.models.ftp_operate import FtpController
class ResMrpWorkOrder(models.Model): class ResMrpWorkOrder(models.Model):
_inherit = 'mrp.workorder' _inherit = 'mrp.workorder'
_order = 'sequence asc'
_description = '工单' _description = '工单'
product_tmpl_name = fields.Char('坯料产品名称', related='production_bom_id.bom_line_ids.product_id.name') product_tmpl_name = fields.Char('坯料产品名称', related='production_bom_id.bom_line_ids.product_id.name')
@@ -1750,6 +1749,35 @@ class ResMrpWorkOrder(models.Model):
self.check_ids.filtered(lambda ch: ch.is_inspect is True and ch.quality_state == 'waiting').write( self.check_ids.filtered(lambda ch: ch.is_inspect is True and ch.quality_state == 'waiting').write(
{'quality_state': 'none'}) {'quality_state': 'none'})
@api.model
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
aggregate_field = 'create_date:max'
if aggregate_field not in fields:
fields.append(aggregate_field)
res = super(ResMrpWorkOrder, self).read_group(
domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy
)
sorted_res = sorted(
res,
key=lambda x: self.parse_datetime(x.get('create_date', '')),
reverse=True
)
return sorted_res
def parse_datetime(self, value):
"""将字符串转换为 datetime 对象,处理空值和无效格式"""
if not value:
return datetime.min # 返回最小日期时间,确保排序稳定
try:
# 假设 value 是字符串(如 "2023-10-01 12:00:00"
return datetime.strptime(value, "%Y-%m-%d %H:%M:%S")
except (TypeError, ValueError):
# 如果已经是 datetime 对象,直接返回
if isinstance(value, datetime):
return value
# 其他无效格式返回最小日期时间
return datetime.min
class CNCprocessing(models.Model): class CNCprocessing(models.Model):
_name = 'sf.cnc.processing' _name = 'sf.cnc.processing'

View File

@@ -755,6 +755,23 @@ class StockPicking(models.Model):
if move_id.product_id.tracking in ['serial', 'lot'] and not move_id.move_line_nosuggest_ids: if move_id.product_id.tracking in ['serial', 'lot'] and not move_id.move_line_nosuggest_ids:
move_id.action_show_details() move_id.action_show_details()
@api.model
def read_group(self, domain, fields, groupby, offset=0, limit=None, orderby=False, lazy=True):
aggregate_field = 'create_date:max'
if aggregate_field not in fields:
fields.append(aggregate_field)
res = super(StockPicking, self).read_group(
domain, fields, groupby, offset=offset, limit=limit, orderby=orderby, lazy=lazy
)
sorted_res = sorted(
res,
key=lambda x: self.env['mrp.workorder'].sudo().parse_datetime(x.get('create_date', '')),
reverse=True
)
return sorted_res
class ReStockMove(models.Model): class ReStockMove(models.Model):
_inherit = 'stock.move' _inherit = 'stock.move'

View File

@@ -455,7 +455,7 @@
<field name="inherit_id" ref="mrp.mrp_production_workorder_tree_editable_view"/> <field name="inherit_id" ref="mrp.mrp_production_workorder_tree_editable_view"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//tree" position="attributes"> <xpath expr="//tree" position="attributes">
<attribute name="default_order">sequence</attribute> <attribute name="default_order">create_date desc</attribute>
<attribute name="decoration-warning">delivery_warning == 'warning'</attribute> <attribute name="decoration-warning">delivery_warning == 'warning'</attribute>
<attribute name="decoration-danger">delivery_warning == 'overdue'</attribute> <attribute name="decoration-danger">delivery_warning == 'overdue'</attribute>
</xpath> </xpath>

View File

@@ -50,6 +50,9 @@
<xpath expr="//field[@name='origin']" position="after"> <xpath expr="//field[@name='origin']" position="after">
<field name="retrospect_ref"/> <field name="retrospect_ref"/>
</xpath> </xpath>
<xpath expr="//tree" position="attributes">
<attribute name="default_order">create_date desc</attribute>
</xpath>
</field> </field>
</record> </record>

View File

@@ -298,6 +298,10 @@
<xpath expr="//field[@name='name']" position="attributes"> <xpath expr="//field[@name='name']" position="attributes">
<attribute name="class">purchase_order_list_name</attribute> <attribute name="class">purchase_order_list_name</attribute>
</xpath> </xpath>
<!-- 修改 tree 视图的排序规则 -->
<xpath expr="//tree" position="attributes">
<attribute name="default_order">date_approve desc</attribute>
</xpath>
</field> </field>
</record> </record>

View File

@@ -14,16 +14,14 @@
<!-- name="Orders"--> <!-- name="Orders"-->
<!-- sequence="10">--> <!-- sequence="10">-->
<!-- <menuitem id="menu_sale_quotations"-->
<!-- action="action_quotations_with_onboarding"-->
<!-- groups="sales_team.group_sale_salesman"-->
<!-- sequence="10"/>-->
<!-- <menuitem id="menu_sale_order"--> <menuitem id="sale.menu_sale_quotations"
<!-- name="Orders"--> parent="sale.sale_order_menu"
<!-- action="action_orders"--> sequence="20"/>
<!-- groups="sales_team.group_sale_salesman"-->
<!-- sequence="20"/>--> <menuitem id="sale.menu_sale_order"
parent="sale.sale_order_menu"
sequence="10"/>
<!-- <menuitem id="report_sales_team"--> <!-- <menuitem id="report_sales_team"-->

View File

@@ -432,7 +432,7 @@
<field name="name">功能刀具组装</field> <field name="name">功能刀具组装</field>
<field name="model">sf.functional.tool.assembly</field> <field name="model">sf.functional.tool.assembly</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree create="0" delete="0"> <tree create="0" delete="0" default_order="create_date desc">
<field name="assembly_order_code"/> <field name="assembly_order_code"/>
<field name="barcode_id" optional="hide"/> <field name="barcode_id" optional="hide"/>
<field name="code" optional="hide"/> <field name="code" optional="hide"/>