未齐套提示
This commit is contained in:
@@ -105,6 +105,18 @@ class sf_production_plan(models.Model):
|
|||||||
default=False
|
default=False
|
||||||
)
|
)
|
||||||
|
|
||||||
|
hide_action_purchase_orders = fields.Boolean(
|
||||||
|
string='显示采购按钮',
|
||||||
|
compute='_compute_hide_action_purchase_orders',
|
||||||
|
default=False
|
||||||
|
)
|
||||||
|
|
||||||
|
hide_action_stock_picking = fields.Boolean(
|
||||||
|
string='显示调拨单按钮',
|
||||||
|
compute='_compute_hide_action_stock_picking',
|
||||||
|
default=False
|
||||||
|
)
|
||||||
|
|
||||||
@api.depends('sale_order_id.state', 'sale_order_id.mrp_production_ids.schedule_state', 'sale_order_id.order_line',
|
@api.depends('sale_order_id.state', 'sale_order_id.mrp_production_ids.schedule_state', 'sale_order_id.order_line',
|
||||||
'sale_order_id.mrp_production_ids.state')
|
'sale_order_id.mrp_production_ids.state')
|
||||||
def _compute_status(self):
|
def _compute_status(self):
|
||||||
@@ -327,14 +339,6 @@ class sf_production_plan(models.Model):
|
|||||||
'target': 'new',
|
'target': 'new',
|
||||||
}
|
}
|
||||||
|
|
||||||
def action_open_sale_order(self):
|
|
||||||
return {
|
|
||||||
'type': 'ir.actions.act_window',
|
|
||||||
'res_model': 'sale.order',
|
|
||||||
'res_id': self.sale_order_id.id,
|
|
||||||
'view_mode': 'form',
|
|
||||||
}
|
|
||||||
|
|
||||||
@api.depends('sale_order_id.mrp_production_ids.state')
|
@api.depends('sale_order_id.mrp_production_ids.state')
|
||||||
def _compute_hide_action_open_mrp_production(self):
|
def _compute_hide_action_open_mrp_production(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
@@ -344,7 +348,45 @@ class sf_production_plan(models.Model):
|
|||||||
record.hide_action_open_mrp_production = bool(mrp_production_ids) and record.supply_method in (
|
record.hide_action_open_mrp_production = bool(mrp_production_ids) and record.supply_method in (
|
||||||
'automation', 'manual')
|
'automation', 'manual')
|
||||||
|
|
||||||
|
def _compute_hide_action_purchase_orders(self):
|
||||||
|
for record in self:
|
||||||
|
record.hide_action_purchase_orders = False
|
||||||
|
if record.material_check == '0' and not record.sale_order_line_id.is_incoming_material:
|
||||||
|
mrp_production = record.sale_order_id.mrp_production_ids.filtered(
|
||||||
|
lambda p: p.product_id.id == record.product_id.id
|
||||||
|
).sorted(key=lambda p: p.id)
|
||||||
|
if mrp_production:
|
||||||
|
pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', mrp_production[0].name)])
|
||||||
|
raw_materials = mrp_production.mapped('move_raw_ids.product_id')
|
||||||
|
if raw_materials:
|
||||||
|
purchase_orders = self.env['purchase.order'].sudo().search([
|
||||||
|
('state', '=', 'purchase'),
|
||||||
|
('order_line.product_id', 'in', raw_materials.ids)
|
||||||
|
])
|
||||||
|
total_purchase_quantity = sum(
|
||||||
|
line.product_qty for order in purchase_orders for line in order.order_line
|
||||||
|
if line.product_id in raw_materials
|
||||||
|
)
|
||||||
|
record.hide_action_purchase_orders = total_purchase_quantity < record.product_uom_qty and pr_ids.state != 'done'
|
||||||
|
|
||||||
|
@api.depends('sale_order_id.mrp_production_ids.picking_ids', 'sale_order_id.mrp_production_ids.picking_ids.state')
|
||||||
|
def _compute_hide_action_stock_picking(self):
|
||||||
|
for record in self:
|
||||||
|
manufacturing_orders = record.sale_order_id.mrp_production_ids
|
||||||
|
record.hide_action_stock_picking = bool(manufacturing_orders.mapped('picking_ids').filtered(
|
||||||
|
lambda p: p.state == 'assigned'))
|
||||||
|
|
||||||
|
def action_open_sale_order(self):
|
||||||
|
self.ensure_one()
|
||||||
|
return {
|
||||||
|
'type': 'ir.actions.act_window',
|
||||||
|
'res_model': 'sale.order',
|
||||||
|
'res_id': self.sale_order_id.id,
|
||||||
|
'view_mode': 'form',
|
||||||
|
}
|
||||||
|
|
||||||
def action_open_mrp_production(self):
|
def action_open_mrp_production(self):
|
||||||
|
self.ensure_one()
|
||||||
mrp_production_ids = self.sale_order_id.mrp_production_ids.filtered(
|
mrp_production_ids = self.sale_order_id.mrp_production_ids.filtered(
|
||||||
lambda p: p.state == 'technology_to_confirmed' and p.product_id.id == self.product_id.id
|
lambda p: p.state == 'technology_to_confirmed' and p.product_id.id == self.product_id.id
|
||||||
).ids
|
).ids
|
||||||
@@ -364,3 +406,39 @@ class sf_production_plan(models.Model):
|
|||||||
'view_mode': 'tree,form',
|
'view_mode': 'tree,form',
|
||||||
})
|
})
|
||||||
return action
|
return action
|
||||||
|
|
||||||
|
def action_view_purchase_request(self):
|
||||||
|
self.ensure_one()
|
||||||
|
first_mp = self.env['mrp.production'].search(
|
||||||
|
[('origin', '=', self.sale_order_id.name)], limit=1, order='id asc')
|
||||||
|
pr_ids = self.env['purchase.request'].sudo().search([('origin', 'like', first_mp.name)])
|
||||||
|
action = {
|
||||||
|
'res_model': 'purchase.request',
|
||||||
|
'type': 'ir.actions.act_window',
|
||||||
|
}
|
||||||
|
if len(pr_ids) == 1:
|
||||||
|
action.update({
|
||||||
|
'view_mode': 'form',
|
||||||
|
'res_id': pr_ids[0].id,
|
||||||
|
})
|
||||||
|
else:
|
||||||
|
action.update({
|
||||||
|
'name': _("从 %s生成采购请求单", self.name),
|
||||||
|
'domain': [('id', 'in', pr_ids)],
|
||||||
|
'view_mode': 'tree,form',
|
||||||
|
})
|
||||||
|
return action
|
||||||
|
|
||||||
|
def action_view_stock_picking(self):
|
||||||
|
self.ensure_one()
|
||||||
|
action = self.env["ir.actions.actions"]._for_xml_id("stock.action_picking_tree_all")
|
||||||
|
picking_ids = self.sale_order_id.mrp_production_ids.mapped('picking_ids').filtered(
|
||||||
|
lambda p: p.state == 'assigned')
|
||||||
|
if len(picking_ids) > 1:
|
||||||
|
action['domain'] = [('id', 'in', picking_ids.ids)]
|
||||||
|
elif picking_ids:
|
||||||
|
action['res_id'] = picking_ids.id
|
||||||
|
action['views'] = [(self.env.ref('stock.view_picking_form').id, 'form')]
|
||||||
|
if 'views' in action:
|
||||||
|
action['views'] += [(state, view) for state, view in action['views'] if view != 'form']
|
||||||
|
return action
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
class="btn-primary"/>
|
class="btn-primary"/>
|
||||||
</header>
|
</header>
|
||||||
<field name="sequence" widget="handle"/>
|
<field name="sequence" widget="handle"/>
|
||||||
|
<field name="id" optional="hide"/>
|
||||||
<field name="priority"/>
|
<field name="priority"/>
|
||||||
<field name="status"/>
|
<field name="status"/>
|
||||||
<field name="partner_id"/>
|
<field name="partner_id"/>
|
||||||
@@ -40,10 +41,16 @@
|
|||||||
<field name="processing_time"/>
|
<field name="processing_time"/>
|
||||||
<field name="material_check"/>
|
<field name="material_check"/>
|
||||||
<field name="hide_action_open_mrp_production" invisible="1"/>
|
<field name="hide_action_open_mrp_production" invisible="1"/>
|
||||||
|
<field name="hide_action_purchase_orders" invisible="1"/>
|
||||||
|
<field name="hide_action_stock_picking" invisible="1"/>
|
||||||
<button name="action_open_sale_order" type="object" string="供货方式待确认" class="btn-primary"
|
<button name="action_open_sale_order" type="object" string="供货方式待确认" class="btn-primary"
|
||||||
attrs="{'invisible': [('supply_method', '!=', False)]}"/>
|
attrs="{'invisible': [('supply_method', '!=', False)]}"/>
|
||||||
<button name="action_open_mrp_production" type="object" string="待工艺确认" class="btn-primary"
|
<button name="action_open_mrp_production" type="object" string="待工艺确认" class="btn-primary"
|
||||||
attrs="{'invisible': [('hide_action_open_mrp_production', '=', False)]}"/>
|
attrs="{'invisible': [('hide_action_open_mrp_production', '=', False)]}"/>
|
||||||
|
<button name="action_view_purchase_request" type="object" string="采购申请" class="btn-primary"
|
||||||
|
attrs="{'invisible': [('hide_action_purchase_orders', '=', False)]}"/>
|
||||||
|
<button name="action_view_stock_picking" type="object" string="调拨单" class="btn-primary"
|
||||||
|
attrs="{'invisible': [('hide_action_stock_picking', '=', False)]}"/>
|
||||||
<field name="planned_start_date"/>
|
<field name="planned_start_date"/>
|
||||||
<field name="actual_start_date"/>
|
<field name="actual_start_date"/>
|
||||||
<field name="actual_end_date"/>
|
<field name="actual_end_date"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user