1、采购订单的关联销售订单字段从销售模块搬迁到制造模块,并新增一个many2many类型字段,且对字段的自动计算方法进行优化。

This commit is contained in:
yuxianghui
2024-12-31 10:56:07 +08:00
parent 32e3c2f79f
commit 4902fc5d9a
4 changed files with 42 additions and 28 deletions

View File

@@ -10,6 +10,7 @@ from odoo.tools import OrderedSet
# _get_surface_technics_purchase_ids # _get_surface_technics_purchase_ids
class PurchaseOrder(models.Model): class PurchaseOrder(models.Model):
_inherit = 'purchase.order' _inherit = 'purchase.order'
production_count = fields.Integer( production_count = fields.Integer(
"关联制造订单", "关联制造订单",
compute='_compute_workorder_count', compute='_compute_workorder_count',
@@ -37,12 +38,12 @@ class PurchaseOrder(models.Model):
}) })
return action return action
def _compute_workorder_count(self): def _compute_workorder_count(self):
for purchase in self: for purchase in self:
origins = [order.name for order in purchase.picking_ids] origins = [order.name for order in purchase.picking_ids]
production_id = self.env['mrp.production'].search([('origin', 'in', origins)]) production_id = self.env['mrp.production'].search([('origin', 'in', origins)])
purchase.production_count = len(production_id) purchase.production_count = len(production_id)
def button_confirm(self): def button_confirm(self):
super().button_confirm() super().button_confirm()
workorders = self.env['mrp.workorder'].search([('purchase_id', '=', self.id), ('state', '!=', 'cancel')]) workorders = self.env['mrp.workorder'].search([('purchase_id', '=', self.id), ('state', '!=', 'cancel')])
@@ -61,10 +62,39 @@ class PurchaseOrder(models.Model):
if not mo.move_line_ids: if not mo.move_line_ids:
self.env['stock.move.line'].create(mo.get_move_line(workorder.production_id, workorder)) self.env['stock.move.line'].create(mo.get_move_line(workorder.production_id, workorder))
return True return True
origin_sale_id = fields.Many2one('sale.order', string='销售订单号', store=True, compute='_compute_origin_sale_id')
origin_sale_ids = fields.Many2many('sale.order', string='销售订单号(多个)', store=True,
compute='_compute_origin_sale_id')
@api.depends('origin')
def _compute_origin_sale_id(self):
for purchase in self:
if not purchase.origin:
continue
elif 'MO' in purchase.origin:
mp_name_list = [name.strip() for name in purchase['origin'].split(',')]
os_ids = list({mp_id.sale_order_id.id for mp_id in self.env['mrp.production'].sudo().search([
('name', 'in', mp_name_list)])})
if len(os_ids) == 1:
purchase.origin_sale_id = os_ids[0]
elif len(os_ids) >= 2:
purchase.origin_sale_ids = os_ids
elif 'S' in purchase.origin:
os_name_list = [name.strip() for name in purchase['origin'].split(',')]
os_ids = self.env['sale.order'].sudo().search([('name', 'in', os_name_list)])
if len(os_ids) == 1:
purchase.origin_sale_id = os_ids.id
elif len(os_ids) >= 2:
purchase.origin_sale_ids = os_ids.ids
class PurchaseOrderLine(models.Model): class PurchaseOrderLine(models.Model):
_inherit = 'purchase.order.line' _inherit = 'purchase.order.line'
part_number = fields.Char('零件图号', related='product_id.part_number', readonly=True) part_number = fields.Char('零件图号', related='product_id.part_number', readonly=True)
related_product = fields.Many2one('product.product',compute='_compute_related_product', string='关联产品',help='经此产品工艺加工成的成品') related_product = fields.Many2one('product.product', compute='_compute_related_product', string='关联产品',
help='经此产品工艺加工成的成品')
@api.depends('order_id.origin') @api.depends('order_id.origin')
def _compute_related_product(self): def _compute_related_product(self):
for record in self: for record in self:
@@ -73,4 +103,3 @@ class PurchaseOrderLine(models.Model):
record.related_product = production_id.product_id if production_id else False record.related_product = production_id.product_id if production_id else False
else: else:
record.related_product = False record.related_product = False

View File

@@ -22,6 +22,13 @@
</div> </div>
</button> </button>
</xpath> </xpath>
<!-- 添加销售订单号字段-->
<xpath expr="//sheet/group/group[2]/div[@name='date_approve']" position="after">
<field name="origin_sale_id" readonly="1" string="参考销售订单"
attrs="{'invisible': [('origin_sale_id' , '=', False)]}"/>
<field name="origin_sale_ids" readonly="1" string="参考销售订单" widget="many2many_tags"
attrs="{'invisible': [('origin_sale_ids' , '=', [])]}"/>
</xpath>
</field> </field>
</record> </record>
</data> </data>

View File

@@ -285,8 +285,6 @@ class RePurchaseOrder(models.Model):
[('standard', '标准采购'), ('consignment', '工序外协'), ('outsourcing', '委外加工'), ('outside', '外购订单')], [('standard', '标准采购'), ('consignment', '工序外协'), ('outsourcing', '委外加工'), ('outside', '外购订单')],
string='采购类型', default='standard', store=True, compute='_compute_purchase_type') string='采购类型', default='standard', store=True, compute='_compute_purchase_type')
origin_sale_id = fields.Many2one('sale.order', string='销售订单号', compute='_compute_origin_sale_id')
# 合同编号 # 合同编号
contract_number = fields.Char(string='合同编号', size=20) contract_number = fields.Char(string='合同编号', size=20)
# 合同概况 # 合同概况
@@ -311,21 +309,6 @@ class RePurchaseOrder(models.Model):
purchase.purchase_type = 'outsourcing' purchase.purchase_type = 'outsourcing'
break break
@api.depends('order_line.move_dest_ids.group_id.mrp_production_ids',
'order_line.move_ids.move_dest_ids.group_id.mrp_production_ids', 'origin')
def _compute_origin_sale_id(self):
for purchase in self:
productions_ids = purchase._get_mrp_productions()
if productions_ids:
if productions_ids[0].sale_order_id:
purchase.origin_sale_id = productions_ids[0].sale_order_id.id
continue
order_id = self.env['sale.order'].sudo().search([('name', '=', purchase.origin)])
if order_id:
purchase.origin_sale_id = order_id.id
continue
purchase.origin_sale_id = False
delivery_warning = fields.Selection([('normal', '正常'), ('warning', '预警'), ('overdue', '已逾期')], delivery_warning = fields.Selection([('normal', '正常'), ('warning', '预警'), ('overdue', '已逾期')],
string='交期状态', default='normal', string='交期状态', default='normal',
tracking=True) tracking=True)

View File

@@ -190,11 +190,6 @@
<field name="partner_ref" string="合同名称"/> <field name="partner_ref" string="合同名称"/>
<field name="contract_number"/> <field name="contract_number"/>
</xpath> </xpath>
<!-- 添加销售订单号字段-->
<xpath expr="//sheet/group/group[2]/div[@name='date_approve']" position="after">
<!-- <field name="origin_sale_id" readonly="1" attrs="{'invisible': [('origin_sale_id', '=', False)]}" string="参考销售订单"/> -->
<field name="origin_sale_id" readonly="1" string="参考销售订单"/>
</xpath>
<xpath expr="//sheet/group/group[2]/field[@name='effective_date']" position="attributes"> <xpath expr="//sheet/group/group[2]/field[@name='effective_date']" position="attributes">
<attribute name="invisible">1</attribute> <attribute name="invisible">1</attribute>
</xpath> </xpath>