下达生产
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from odoo import models, fields, api, _
|
from odoo import models, fields, api, _
|
||||||
from odoo.exceptions import ValidationError
|
from odoo.exceptions import ValidationError
|
||||||
|
from odoo.tools import float_compare
|
||||||
|
|
||||||
|
|
||||||
class sf_production_plan(models.Model):
|
class sf_production_plan(models.Model):
|
||||||
@@ -215,16 +216,18 @@ class sf_production_plan(models.Model):
|
|||||||
record.actual_end_date = None
|
record.actual_end_date = None
|
||||||
|
|
||||||
@api.depends('sale_order_id.mrp_production_ids.move_raw_ids.forecast_availability',
|
@api.depends('sale_order_id.mrp_production_ids.move_raw_ids.forecast_availability',
|
||||||
'sale_order_id.mrp_production_ids.move_raw_ids.product_uom_qty')
|
'sale_order_id.mrp_production_ids.move_raw_ids.quantity_done')
|
||||||
def _compute_material_check(self):
|
def _compute_material_check(self):
|
||||||
for record in self:
|
for record in self:
|
||||||
if record.sale_order_id and record.sale_order_id.mrp_production_ids:
|
if record.sale_order_id and record.sale_order_id.mrp_production_ids:
|
||||||
manufacturing_orders = record.sale_order_id.mrp_production_ids.filtered(
|
manufacturing_orders = record.sale_order_id.mrp_production_ids.filtered(
|
||||||
lambda mo: mo.product_id == record.product_id)
|
lambda mo: mo.product_id == record.product_id)
|
||||||
if manufacturing_orders:
|
if manufacturing_orders and manufacturing_orders.move_raw_ids:
|
||||||
total_reserved = sum(mo.forecast_availability for mo in manufacturing_orders)
|
total_forecast_availability = sum(manufacturing_orders.mapped('move_raw_ids.forecast_availability'))
|
||||||
total_to_consume = sum(mo.product_uom_qty for mo in manufacturing_orders)
|
total_quantity_done = sum(manufacturing_orders.mapped('move_raw_ids.quantity_done'))
|
||||||
if total_reserved >= total_to_consume:
|
total_sum = total_forecast_availability + total_quantity_done
|
||||||
|
if float_compare(total_sum, record.product_uom_qty,
|
||||||
|
precision_rounding=record.product_id.uom_id.rounding) >= 0:
|
||||||
record.material_check = '1' # 已齐套
|
record.material_check = '1' # 已齐套
|
||||||
else:
|
else:
|
||||||
record.material_check = '0' # 未齐套
|
record.material_check = '0' # 未齐套
|
||||||
@@ -238,3 +241,6 @@ class sf_production_plan(models.Model):
|
|||||||
for record in self:
|
for record in self:
|
||||||
if record.planned_start_date and record.planned_start_date < fields.Date.today():
|
if record.planned_start_date and record.planned_start_date < fields.Date.today():
|
||||||
raise ValidationError("计划开工日期必须大于或等于今天。")
|
raise ValidationError("计划开工日期必须大于或等于今天。")
|
||||||
|
|
||||||
|
def release_production_order(self):
|
||||||
|
pass
|
||||||
|
|||||||
@@ -43,6 +43,8 @@
|
|||||||
<field name="write_date" string="更新时间"/>
|
<field name="write_date" string="更新时间"/>
|
||||||
<field name="write_uid" optional="hide" string="更新人"/>
|
<field name="write_uid" optional="hide" string="更新人"/>
|
||||||
<field name="print_count"/>
|
<field name="print_count"/>
|
||||||
|
<button name="release_production_order" type="object" string="下达生产" class="btn-primary"
|
||||||
|
attrs="{'invisible': ['|',('status', '!=', '30'), ('supply_method', 'not in', ['automation', 'manual'])]}"/>
|
||||||
</tree>
|
</tree>
|
||||||
</field>
|
</field>
|
||||||
</record>
|
</record>
|
||||||
|
|||||||
Reference in New Issue
Block a user