需求计划供货方式修改
This commit is contained in:
@@ -40,7 +40,8 @@ class ReSaleOrder(models.Model):
|
||||
'sale_order_line_id': ret.id,
|
||||
}
|
||||
demand_plan_info = self.env['sf.demand.plan'].sudo().create(vals)
|
||||
vals.update({'demand_plan_id': demand_plan_info.id, 'plan_uom_qty': ret.product_uom_qty})
|
||||
vals.update({'demand_plan_id': demand_plan_info.id, 'plan_uom_qty': ret.product_uom_qty,
|
||||
'new_supply_method': 'custom_made', 'custom_made_type': 'manual'})
|
||||
demand_plan = self.env['sf.production.demand.plan'].sudo().create(vals)
|
||||
demand_plan_info.write({'line_ids': demand_plan.ids})
|
||||
if demand_plan.product_id.machining_drawings_name:
|
||||
|
||||
@@ -9,11 +9,6 @@ class SfDemandPlan(models.Model):
|
||||
_name = 'sf.demand.plan'
|
||||
_description = 'sf_demand_plan'
|
||||
|
||||
def _get_machining_precision(self):
|
||||
machinings = self.env['sf.machining.accuracy'].sudo().search([])
|
||||
list = [(m.sync_id, m.name) for m in machinings]
|
||||
return list
|
||||
|
||||
state = fields.Selection([
|
||||
('10', '需求确认'),
|
||||
('20', '待工艺设计'),
|
||||
@@ -64,9 +59,7 @@ class SfDemandPlan(models.Model):
|
||||
compute='_compute_model_process_parameters_ids'
|
||||
, store=True
|
||||
)
|
||||
model_machining_precision = fields.Selection(selection=_get_machining_precision, string='精度',
|
||||
related='product_id.model_machining_precision')
|
||||
|
||||
model_machining_precision = fields.Selection(related='product_id.model_machining_precision', string='精度')
|
||||
inventory_quantity_auto_apply = fields.Float(
|
||||
string="成品库存",
|
||||
compute='_compute_inventory_quantity_auto_apply', store=True
|
||||
@@ -85,6 +78,12 @@ class SfDemandPlan(models.Model):
|
||||
default=False
|
||||
)
|
||||
|
||||
readonly_custom_made_type = fields.Boolean(
|
||||
string='字段自制类型只读',
|
||||
compute='_compute_readonly_custom_made_type',
|
||||
default=False
|
||||
)
|
||||
|
||||
@api.depends('product_id.part_number', 'product_id.model_name')
|
||||
def _compute_part_number(self):
|
||||
for line in self:
|
||||
@@ -181,17 +180,18 @@ class SfDemandPlan(models.Model):
|
||||
else:
|
||||
line.state = '10'
|
||||
|
||||
@api.depends('line_ids.status')
|
||||
def _compute_readonly_custom_made_type(self):
|
||||
for line in self:
|
||||
production_demand_plan = line.line_ids.filtered(
|
||||
lambda p: p.status in ('50', '60') and p.new_supply_method == 'custom_made')
|
||||
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")
|
||||
if 'line_ids' in vals:
|
||||
for line in self.line_ids:
|
||||
if not line.sale_order_id:
|
||||
line.sale_order_id = self.sale_order_id
|
||||
if not line.sale_order_line_id:
|
||||
line.sale_order_line_id = self.sale_order_line_id
|
||||
return res
|
||||
|
||||
def name_get(self):
|
||||
|
||||
@@ -17,17 +17,7 @@ class SfProductionDemandPlan(models.Model):
|
||||
stock_location = self.env['stock.location'].sudo().search([('name', '=', '客户')], limit=1)
|
||||
return stock_location.id
|
||||
|
||||
def _get_machining_precision(self):
|
||||
machinings = self.env['sf.machining.accuracy'].sudo().search([])
|
||||
list = [(m.sync_id, m.name) for m in machinings]
|
||||
return list
|
||||
|
||||
priority = fields.Selection([
|
||||
('1', '紧急'),
|
||||
('2', '高'),
|
||||
('3', '中'),
|
||||
('4', '低'),
|
||||
], string='优先级', related='demand_plan_id.priority')
|
||||
priority = fields.Selection(related='demand_plan_id.priority', string='优先级')
|
||||
status = fields.Selection([
|
||||
('10', '草稿'),
|
||||
('20', '待确认'),
|
||||
@@ -38,9 +28,9 @@ class SfProductionDemandPlan(models.Model):
|
||||
], string='状态', default='30', readonly=True)
|
||||
demand_plan_id = fields.Many2one(comodel_name="sf.demand.plan",
|
||||
string="物料需求", readonly=True)
|
||||
sale_order_id = fields.Many2one(comodel_name="sale.order",
|
||||
sale_order_id = fields.Many2one(comodel_name="sale.order", related='demand_plan_id.sale_order_id',
|
||||
string="销售订单", readonly=True)
|
||||
sale_order_line_id = fields.Many2one(comodel_name="sale.order.line",
|
||||
sale_order_line_id = fields.Many2one(comodel_name="sale.order.line", related='demand_plan_id.sale_order_line_id',
|
||||
string="销售订单明细", readonly=True)
|
||||
sale_order_line_number = fields.Char(string='销售订单行', compute='_compute_sale_order_line_number', store=True)
|
||||
company_id = fields.Many2one(
|
||||
@@ -58,12 +48,24 @@ class SfProductionDemandPlan(models.Model):
|
||||
part_name = fields.Char('零件名称', related='product_id.part_name')
|
||||
part_number = fields.Char('零件图号', related='demand_plan_id.part_number')
|
||||
is_incoming_material = fields.Boolean('客供料', related='sale_order_line_id.is_incoming_material', store=True)
|
||||
|
||||
new_supply_method = fields.Selection([
|
||||
('custom_made', "自制"),
|
||||
('purchase', "外购"),
|
||||
('outsourcing', "委外加工"),
|
||||
], string='供货方式', readonly=True)
|
||||
|
||||
custom_made_type = fields.Selection([
|
||||
('automation', "自动化产线加工"),
|
||||
('manual', "人工线下加工"),
|
||||
], string='自制类型', compute='_compute_custom_made_type', store=True)
|
||||
|
||||
supply_method = fields.Selection([
|
||||
('automation', "自动化产线加工"),
|
||||
('manual', "人工线下加工"),
|
||||
('purchase', "外购"),
|
||||
('outsourcing', "委外加工"),
|
||||
], string='供货方式', default='manual')
|
||||
], string='供货方式', compute='_compute_supply_method', store=True, readonly=True)
|
||||
product_uom_qty = fields.Float(
|
||||
string="需求数量",
|
||||
related='sale_order_line_id.product_uom_qty', store=True)
|
||||
@@ -79,11 +81,11 @@ class SfProductionDemandPlan(models.Model):
|
||||
model_long = fields.Char('尺寸(mm)', compute='_compute_model_long')
|
||||
blank_type = fields.Selection([('圆料', '圆料'), ('方料', '方料')], string='坯料分类',
|
||||
related='product_id.blank_type')
|
||||
blank_precision = fields.Selection([('精坯', '精坯'), ('粗坯', '粗坯')], string='坯料类型', related='product_id.blank_precision')
|
||||
blank_precision = fields.Selection([('精坯', '精坯'), ('粗坯', '粗坯')], string='坯料类型',
|
||||
related='product_id.blank_precision')
|
||||
embryo_long = fields.Char('坯料尺寸(mm)', related='demand_plan_id.embryo_long')
|
||||
materials_id = fields.Char('材料', related='demand_plan_id.materials_id')
|
||||
model_machining_precision = fields.Selection(selection=_get_machining_precision, string='精度',
|
||||
related='product_id.model_machining_precision')
|
||||
model_machining_precision = fields.Selection(related='product_id.model_machining_precision', string='精度')
|
||||
model_process_parameters_ids = fields.Many2many(related='demand_plan_id.model_process_parameters_ids',
|
||||
string='表面工艺', )
|
||||
product_remark = fields.Char("产品备注", related='product_id.model_remark')
|
||||
@@ -121,6 +123,11 @@ class SfProductionDemandPlan(models.Model):
|
||||
default=False
|
||||
)
|
||||
|
||||
readonly_custom_made_type = fields.Boolean(
|
||||
related='demand_plan_id.readonly_custom_made_type',
|
||||
string='字段自制类型只读'
|
||||
)
|
||||
|
||||
# hide_action_open_mrp_production = fields.Boolean(
|
||||
# string='显示待工艺确认按钮',
|
||||
# compute='_compute_hid_button',
|
||||
@@ -165,6 +172,30 @@ class SfProductionDemandPlan(models.Model):
|
||||
bom_id = fields.Many2one('mrp.bom', string="BOM", readonly=True)
|
||||
location_id = fields.Many2one('stock.location', string='需求位置', default=get_location_id, readonly=True)
|
||||
|
||||
@api.depends('new_supply_method')
|
||||
def _compute_custom_made_type(self):
|
||||
DemandPlan = self.env['sf.production.demand.plan'].sudo()
|
||||
for line in self:
|
||||
if line.new_supply_method != "custom_made":
|
||||
line.custom_made_type = False
|
||||
else:
|
||||
demand_plan_id = line.demand_plan_id._origin.id
|
||||
demand_plan = DemandPlan.search([
|
||||
('demand_plan_id', '=', demand_plan_id),
|
||||
('new_supply_method', '=', 'custom_made'),
|
||||
('status', 'in', ('50', '60'))
|
||||
], limit=1)
|
||||
if demand_plan:
|
||||
line.custom_made_type = demand_plan.custom_made_type
|
||||
|
||||
@api.depends('new_supply_method', 'custom_made_type')
|
||||
def _compute_supply_method(self):
|
||||
for line in self:
|
||||
if line.new_supply_method == 'custom_made':
|
||||
line.supply_method = line.custom_made_type
|
||||
else:
|
||||
line.supply_method = line.new_supply_method
|
||||
|
||||
@api.depends('supply_method')
|
||||
def _compute_route_ids(self):
|
||||
for pdp in self:
|
||||
@@ -549,7 +580,7 @@ class SfProductionDemandPlan(models.Model):
|
||||
|
||||
def button_release_plan(self):
|
||||
self.ensure_one()
|
||||
if not self.supply_method:
|
||||
if not self.new_supply_method:
|
||||
raise ValidationError(f"供货方式不能为空!")
|
||||
if self.plan_uom_qty > self.product_uom_qty:
|
||||
return {
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<field name="model">sf.production.demand.plan</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="需求计划" default_order="sequence desc,id desc" editable="bottom"
|
||||
class="demand_plan_tree freeze-columns-before-part_number" create="false" delete="false">
|
||||
class="demand_plan_tree freeze-columns-before-part_number" create="false" delete="false">
|
||||
<header>
|
||||
<button string="打印" name="button_action_print" type="object"
|
||||
class="btn-primary"/>
|
||||
@@ -20,7 +20,11 @@
|
||||
<field name="part_name"/>
|
||||
<field name="part_number"/>
|
||||
<field name="is_incoming_material"/>
|
||||
<field name="supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||
<field name="new_supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||
<field name="readonly_custom_made_type" invisible="1"/>
|
||||
<field name="custom_made_type"
|
||||
attrs="{'readonly': ['|',('status', '!=', '30'),('readonly_custom_made_type', '=', True)],
|
||||
'required': [('new_supply_method', '=', 'custom_made')]}"/>
|
||||
<field name="product_uom_qty"/>
|
||||
<field name="deadline_of_delivery"/>
|
||||
<field name="inventory_quantity_auto_apply"/>
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<form>
|
||||
<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)]}"/>-->
|
||||
<!-- <button string="下达计划" name="button_release_plan" type="object"-->
|
||||
<!-- class="btn-primary" attrs="{'invisible': [('hide_button_release_plan', '=', False)]}"/>-->
|
||||
<field name="state" widget="statusbar"/>
|
||||
</header>
|
||||
<sheet>
|
||||
@@ -41,11 +41,17 @@
|
||||
<field name="line_ids" attrs="{'readonly': [('state', 'in', ('40','50'))]}">
|
||||
<tree editable="bottom" delete="false">
|
||||
<field name="status"/>
|
||||
<field name="supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||
<field name="readonly_custom_made_type" invisible="1"/>
|
||||
<field name="new_supply_method" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||
<field name="custom_made_type"
|
||||
attrs="{
|
||||
'readonly': ['|', '|', ('new_supply_method', '!=', 'custom_made'), ('status', '!=', '30'), ('readonly_custom_made_type', '=', True)],
|
||||
'required': [('new_supply_method', '=', 'custom_made')]}"/>
|
||||
<field name="supply_method"/>
|
||||
<field name="route_ids" widget="many2many_tags" optional="hide"/>
|
||||
<field name="location_id" optional="hide"/>
|
||||
<field name="bom_id" optional="hide"/>
|
||||
<field name="plan_uom_qty"/>
|
||||
<field name="plan_uom_qty" attrs="{'readonly': [('status', '!=', '30')]}"/>
|
||||
<field name="blank_arrival_date"/>
|
||||
<field name="finished_product_arrival_date"/>
|
||||
<field name="planned_start_date"/>
|
||||
|
||||
Reference in New Issue
Block a user