需求计划下达计划
This commit is contained in:
@@ -21,6 +21,6 @@ class MrpProduction(models.Model):
|
|||||||
production.production_type = None
|
production.production_type = None
|
||||||
|
|
||||||
def _get_purchase_request(self):
|
def _get_purchase_request(self):
|
||||||
"""获取跟制造订单相关的采购申请单"""
|
"""获取跟制造订单相关的采购申请单(根据采购申请单行项目的产品匹配)"""
|
||||||
pr_ids = self.env['purchase.request'].sudo().search([('origin', '=', self.name)])
|
pr_ids = self.env['purchase.request'].sudo().search([('line_ids.demand_plan_line_id', 'in', self.demand_plan_line_id.ids)])
|
||||||
return pr_ids
|
return pr_ids
|
||||||
|
|||||||
@@ -161,7 +161,7 @@ class SfDemandPlan(models.Model):
|
|||||||
def _compute_hide_button_release_plan(self):
|
def _compute_hide_button_release_plan(self):
|
||||||
for line in self:
|
for line in self:
|
||||||
line.hide_button_release_plan = bool(line.line_ids.filtered(
|
line.hide_button_release_plan = bool(line.line_ids.filtered(
|
||||||
lambda p: p.status != '60'))
|
lambda p: p.status == '30'))
|
||||||
|
|
||||||
def button_release_plan(self):
|
def button_release_plan(self):
|
||||||
pass
|
pass
|
||||||
@@ -187,15 +187,28 @@ class SfDemandPlan(models.Model):
|
|||||||
lambda p: p.status in ('50', '60') and p.new_supply_method == 'custom_made')
|
lambda p: p.status in ('50', '60') and p.new_supply_method == 'custom_made')
|
||||||
line.readonly_custom_made_type = bool(production_demand_plan)
|
line.readonly_custom_made_type = bool(production_demand_plan)
|
||||||
|
|
||||||
def write(self, vals):
|
|
||||||
res = super(SfDemandPlan, self).write(vals)
|
|
||||||
line_ids = self.line_ids.filtered(lambda p: p.plan_uom_qty == 0 or p.plan_uom_qty < 0)
|
|
||||||
if line_ids:
|
|
||||||
raise ValidationError(f"计划量不能小于等于0")
|
|
||||||
return res
|
|
||||||
|
|
||||||
def name_get(self):
|
def name_get(self):
|
||||||
result = []
|
result = []
|
||||||
for plan in self:
|
for plan in self:
|
||||||
result.append((plan.id, plan.sale_order_id.name))
|
result.append((plan.id, plan.sale_order_id.name))
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
def button_batch_release_plan(self):
|
||||||
|
line_ids = self.line_ids.filtered(lambda p: p.status == '30')
|
||||||
|
sum_product_uom_qty = sum(line_ids.mapped('plan_uom_qty'))
|
||||||
|
if sum_product_uom_qty > self.product_uom_qty:
|
||||||
|
return {
|
||||||
|
'name': _('需求计划'),
|
||||||
|
'type': 'ir.actions.act_window',
|
||||||
|
'views': [(self.env.ref(
|
||||||
|
'sf_demand_plan.sf_release_plan_wizard_form').id,
|
||||||
|
'form')],
|
||||||
|
'res_model': 'sf.release.plan.wizard',
|
||||||
|
'target': 'new',
|
||||||
|
'context': {
|
||||||
|
'default_demand_plan_line_id': line_ids.ids,
|
||||||
|
'default_release_message': f"您正在下达计划量 {sum_product_uom_qty},需求数量为 {self.product_uom_qty},已超过需求数量,是否继续?",
|
||||||
|
}}
|
||||||
|
else:
|
||||||
|
for demand_plan_line_id in line_ids:
|
||||||
|
demand_plan_line_id.action_confirm()
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
('custom_made', "自制"),
|
('custom_made', "自制"),
|
||||||
('purchase', "外购"),
|
('purchase', "外购"),
|
||||||
('outsourcing', "委外加工"),
|
('outsourcing', "委外加工"),
|
||||||
], string='供货方式', readonly=True)
|
], string='供货方式', required=True)
|
||||||
|
|
||||||
custom_made_type = fields.Selection([
|
custom_made_type = fields.Selection([
|
||||||
('automation', "自动化产线加工"),
|
('automation', "自动化产线加工"),
|
||||||
@@ -160,7 +160,7 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
#
|
#
|
||||||
# outsourcing_purchase_request = fields.Char('委外采购申请单')
|
# outsourcing_purchase_request = fields.Char('委外采购申请单')
|
||||||
|
|
||||||
plan_uom_qty = fields.Float(string="计划量")
|
plan_uom_qty = fields.Float(string="计划量", required=True)
|
||||||
procurement_reason = fields.Selection([
|
procurement_reason = fields.Selection([
|
||||||
('销售订单', "销售订单"),
|
('销售订单', "销售订单"),
|
||||||
('需求预测', "需求预测"),
|
('需求预测', "需求预测"),
|
||||||
@@ -172,6 +172,11 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
bom_id = fields.Many2one('mrp.bom', string="BOM", readonly=True)
|
bom_id = fields.Many2one('mrp.bom', string="BOM", readonly=True)
|
||||||
location_id = fields.Many2one('stock.location', string='需求位置', default=get_location_id, readonly=True)
|
location_id = fields.Many2one('stock.location', string='需求位置', default=get_location_id, readonly=True)
|
||||||
|
|
||||||
|
@api.onchange('plan_uom_qty')
|
||||||
|
def _onchange_plan_uom_qty(self):
|
||||||
|
if self.plan_uom_qty == 0 or self.plan_uom_qty < 0:
|
||||||
|
raise ValidationError(_("计划量不能小于等于0"))
|
||||||
|
|
||||||
@api.depends('new_supply_method')
|
@api.depends('new_supply_method')
|
||||||
def _compute_custom_made_type(self):
|
def _compute_custom_made_type(self):
|
||||||
DemandPlan = self.env['sf.production.demand.plan'].sudo()
|
DemandPlan = self.env['sf.production.demand.plan'].sudo()
|
||||||
@@ -592,7 +597,7 @@ class SfProductionDemandPlan(models.Model):
|
|||||||
'res_model': 'sf.release.plan.wizard',
|
'res_model': 'sf.release.plan.wizard',
|
||||||
'target': 'new',
|
'target': 'new',
|
||||||
'context': {
|
'context': {
|
||||||
'default_demand_plan_line_id': self.id,
|
'default_demand_plan_line_id': self.ids,
|
||||||
'default_release_message': f"您正在下达计划量 {self.plan_uom_qty},需求数量为 {self.product_uom_qty},已超过需求数量,是否继续?",
|
'default_release_message': f"您正在下达计划量 {self.plan_uom_qty},需求数量为 {self.product_uom_qty},已超过需求数量,是否继续?",
|
||||||
}}
|
}}
|
||||||
self.action_confirm()
|
self.action_confirm()
|
||||||
|
|||||||
@@ -8,6 +8,10 @@
|
|||||||
<header>
|
<header>
|
||||||
<button string="打印" name="button_action_print" type="object"
|
<button string="打印" name="button_action_print" type="object"
|
||||||
class="btn-primary"/>
|
class="btn-primary"/>
|
||||||
|
<button string="下达计划" name="button_release_plan" type="object"
|
||||||
|
class="btn-primary"
|
||||||
|
attrs="{'invisible': [('status', 'in', ('50','60','100'))]}"
|
||||||
|
/>
|
||||||
</header>
|
</header>
|
||||||
<field name="sequence" widget="handle"/>
|
<field name="sequence" widget="handle"/>
|
||||||
<field name="id" optional="hide"/>
|
<field name="id" optional="hide"/>
|
||||||
@@ -26,6 +30,7 @@
|
|||||||
attrs="{'readonly': ['|',('status', '!=', '30'),('readonly_custom_made_type', '=', True)],
|
attrs="{'readonly': ['|',('status', '!=', '30'),('readonly_custom_made_type', '=', True)],
|
||||||
'required': [('new_supply_method', '=', 'custom_made')]}"/>
|
'required': [('new_supply_method', '=', 'custom_made')]}"/>
|
||||||
<field name="product_uom_qty"/>
|
<field name="product_uom_qty"/>
|
||||||
|
<field name="plan_uom_qty" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||||
<field name="deadline_of_delivery"/>
|
<field name="deadline_of_delivery"/>
|
||||||
<field name="inventory_quantity_auto_apply"/>
|
<field name="inventory_quantity_auto_apply"/>
|
||||||
<field name="qty_delivered"/>
|
<field name="qty_delivered"/>
|
||||||
@@ -77,6 +82,10 @@
|
|||||||
<field name="write_uid" optional="hide" string="更新人"/>
|
<field name="write_uid" optional="hide" string="更新人"/>
|
||||||
<field name="print_count"/>
|
<field name="print_count"/>
|
||||||
<field name="hide_release_production_order" invisible="1"/>
|
<field name="hide_release_production_order" invisible="1"/>
|
||||||
|
<button string="下达计划" name="button_release_plan" type="object"
|
||||||
|
class="btn-primary"
|
||||||
|
attrs="{'invisible': [('status', 'in', ('50','60','100'))]}"
|
||||||
|
/>
|
||||||
<button name="button_release_production" type="object" string="下发生产" class="btn-primary"
|
<button name="button_release_production" type="object" string="下发生产" class="btn-primary"
|
||||||
attrs="{'invisible': [('hide_release_production_order', '=', False)]}"
|
attrs="{'invisible': [('hide_release_production_order', '=', False)]}"
|
||||||
/>
|
/>
|
||||||
|
|||||||
@@ -5,10 +5,11 @@
|
|||||||
<field name="arch" type="xml">
|
<field name="arch" type="xml">
|
||||||
<form>
|
<form>
|
||||||
<header>
|
<header>
|
||||||
<field name="hide_button_release_plan" invisible="1"/>
|
|
||||||
<!-- <button string="下达计划" name="button_release_plan" type="object"-->
|
|
||||||
<!-- class="btn-primary" attrs="{'invisible': [('hide_button_release_plan', '=', False)]}"/>-->
|
|
||||||
<field name="state" widget="statusbar"/>
|
<field name="state" widget="statusbar"/>
|
||||||
|
<field name="hide_button_release_plan" invisible="1"/>
|
||||||
|
<button string="下达计划" name="button_batch_release_plan" type="object"
|
||||||
|
class="btn-primary"
|
||||||
|
attrs="{'invisible': [('hide_button_release_plan', '=', False)]}"/>
|
||||||
</header>
|
</header>
|
||||||
<sheet>
|
<sheet>
|
||||||
<group>
|
<group>
|
||||||
@@ -47,7 +48,6 @@
|
|||||||
attrs="{
|
attrs="{
|
||||||
'readonly': ['|', '|', ('new_supply_method', '!=', 'custom_made'), ('status', '!=', '30'), ('readonly_custom_made_type', '=', True)],
|
'readonly': ['|', '|', ('new_supply_method', '!=', 'custom_made'), ('status', '!=', '30'), ('readonly_custom_made_type', '=', True)],
|
||||||
'required': [('new_supply_method', '=', 'custom_made')]}"/>
|
'required': [('new_supply_method', '=', 'custom_made')]}"/>
|
||||||
<field name="supply_method"/>
|
|
||||||
<field name="route_ids" widget="many2many_tags" optional="hide"/>
|
<field name="route_ids" widget="many2many_tags" optional="hide"/>
|
||||||
<field name="location_id" optional="hide"/>
|
<field name="location_id" optional="hide"/>
|
||||||
<field name="bom_id" optional="hide"/>
|
<field name="bom_id" optional="hide"/>
|
||||||
|
|||||||
@@ -9,14 +9,12 @@ class SfReleasePlanWizard(models.TransientModel):
|
|||||||
_name = 'sf.release.plan.wizard'
|
_name = 'sf.release.plan.wizard'
|
||||||
_description = u'下达计划向导'
|
_description = u'下达计划向导'
|
||||||
|
|
||||||
demand_plan_id = fields.Many2one(comodel_name="sf.demand.plan",
|
demand_plan_line_id = fields.Many2many(comodel_name="sf.production.demand.plan",
|
||||||
string="需求计划", readonly=True)
|
|
||||||
|
|
||||||
demand_plan_line_id = fields.Many2one(comodel_name="sf.production.demand.plan",
|
|
||||||
string="需求计划明细", readonly=True)
|
string="需求计划明细", readonly=True)
|
||||||
|
|
||||||
release_message = fields.Char(string='提示', readonly=True)
|
release_message = fields.Char(string='提示', readonly=True)
|
||||||
|
|
||||||
def confirm(self):
|
def confirm(self):
|
||||||
if self.demand_plan_line_id:
|
if self.demand_plan_line_id:
|
||||||
self.demand_plan_line_id.action_confirm()
|
for demand_plan_line_id in self.demand_plan_line_id:
|
||||||
|
demand_plan_line_id.action_confirm()
|
||||||
|
|||||||
Reference in New Issue
Block a user