新增根据模型类型计算出产品的胚料尺寸

This commit is contained in:
jinling.yang
2022-10-31 17:34:44 +08:00
parent 002653957e
commit 7067b29735
6 changed files with 73 additions and 53 deletions

View File

@@ -6,7 +6,7 @@ class ModelType(models.Model):
_description = '模型类型' _description = '模型类型'
name = fields.Char('名称') name = fields.Char('名称')
routing_tmpl_id = fields.One2many('mrp.routing.workcenter', 'model_type_id', '工序模板') routing_tmpl_id = fields.One2many('sf.model.type.routing.sort', 'model_type_id', '工序模板')
class ResMrpRoutingWorkcenter(models.Model): class ResMrpRoutingWorkcenter(models.Model):
@@ -16,5 +16,16 @@ class ResMrpRoutingWorkcenter(models.Model):
is_repeat = fields.Boolean('重复', default=False) is_repeat = fields.Boolean('重复', default=False)
workcenter_id = fields.Many2many('mrp.workcenter', required=False) workcenter_id = fields.Many2many('mrp.workcenter', required=False)
bom_id = fields.Many2one('mrp.bom', required=False) bom_id = fields.Many2one('mrp.bom', required=False)
sort = fields.Integer('排序') route_workcenter_sort_id = fields.Many2many('sf.model.type.routing.sort')
class ModelTypeRoutingSort(models.Model):
_name = 'sf.model.type.routing.sort'
_description = '工序排序'
sequence = fields.Integer('Sequence')
route_workcenter_id = fields.Many2many('mrp.routing.workcenter')
model_type_id = fields.Many2one('sf.model.type') model_type_id = fields.Many2one('sf.model.type')

View File

@@ -1,4 +1,4 @@
from odoo import models, fields from odoo import models, fields,api
from odoo.exceptions import ValidationError from odoo.exceptions import ValidationError
@@ -45,6 +45,22 @@ class ResProductTemplate(models.Model):
copy_product_id.sudo().write(vals) copy_product_id.sudo().write(vals)
return copy_product_id return copy_product_id
# 在产品上增加模型类型和加工的面例如A、B)
# 并根据模型类型计算出产品的胚料尺寸;
@api.onchange('model_type_id')
def count_embryo_size(self):
bom = self.env['mrp.bom.line'].search(
[('product_tmpl_id', '=', self.id)])
for item in self:
print(bom.product_tmpl_id)
print(bom.model_long)
item.model_long = bom.model_long + 1
print(item.model_long)
item.embryo_width = bom.embryo_width + 1
item.embryo_height = bom.embryo_height + 1
class ResProductCategory(models.Model): class ResProductCategory(models.Model):
_inherit = "product.category" _inherit = "product.category"
@@ -94,3 +110,7 @@ class ResMrpBom(models.Model):

View File

@@ -14,6 +14,7 @@ access_mrs_materials_model,mrs_materials_model,model_mrs_materials_model,base.gr
access_mrs_processing_technology,mrs_processing_technology,model_mrs_processing_technology,base.group_user,1,1,1,1 access_mrs_processing_technology,mrs_processing_technology,model_mrs_processing_technology,base.group_user,1,1,1,1
access_sf_tray,sf_tray,model_sf_tray,base.group_user,1,1,1,1 access_sf_tray,sf_tray,model_sf_tray,base.group_user,1,1,1,1
access_sf_model_type,sf_model_type,model_sf_model_type,base.group_user,1,1,1,1 access_sf_model_type,sf_model_type,model_sf_model_type,base.group_user,1,1,1,1
access_sf_model_type_routing_sort,sf_model_type_routing_sort,model_sf_model_type_routing_sort,base.group_user,1,1,1,1
1 id name model_id:id group_id:id perm_read perm_write perm_create perm_unlink
14 access_sf_tray sf_tray model_sf_tray base.group_user 1 1 1 1
15 access_sf_model_type sf_model_type model_sf_model_type base.group_user 1 1 1 1
16 access_sf_model_type_routing_sort sf_model_type_routing_sort model_sf_model_type_routing_sort base.group_user 1 1 1 1
17
18
19
20

View File

@@ -523,16 +523,13 @@
<field name="name" required="1"/> <field name="name" required="1"/>
</group> </group>
<group> <group>
<field name="routing_tmpl_id" required="1"> <!-- <field name='routing_tmpl_id' options="{'no_create':True}" widget="one2many">-->
<tree editable="bottom"> <!-- <tree editable='bottom'>-->
<field name="sequence" invisible="1"/> <!-- <field name="sequence" widget="handle"/>-->
<field name="name" /> <!-- <field name="route_workcenter_id" widget="many2many_tags">-->
<field name="workcenter_id" /> <!-- <field name="model_type_id" widget="many2many_tags">-->
<field name="time_mode" /> <!-- </tree>-->
<field name="time_cycle" /> <!-- </field>-->
<!-- <field name="bom_id" invisible="1"/>-->
</tree>
</field>
</group> </group>
</form> </form>
</field> </field>

View File

@@ -7,40 +7,42 @@ from odoo.addons.stock.models.stock_rule import ProcurementException
from odoo.tools import float_compare, OrderedSet from odoo.tools import float_compare, OrderedSet
class StockRule(models.Model): class ReStockRule(models.Model):
_inherit = 'stock.rule' _inherit = 'stock.rule'
def _run_manufacture(self, procurements):
productions_values_by_company = defaultdict(list)
errors = []
for procurement, rule in procurements:
if float_compare(procurement.product_qty, 0, precision_rounding=procurement.product_uom.rounding) <= 0:
# If procurement contains negative quantity, don't create a MO that would be for a negative value.
continue
bom = rule._get_matching_bom(procurement.product_id, procurement.company_id, procurement.values)
def _run_manufacture(self, procurements): productions_values_by_company[procurement.company_id.id].append(rule._prepare_mo_vals(*procurement, bom))
productions_values_by_company = defaultdict(list)
errors = []
for procurement, rule in procurements:
if float_compare(procurement.product_qty, 0, precision_rounding=procurement.product_uom.rounding) <= 0:
# If procurement contains negative quantity, don't create a MO that would be for a negative value.
continue
bom = rule._get_matching_bom(procurement.product_id, procurement.company_id, procurement.values)
productions_values_by_company[procurement.company_id.id].append(rule._prepare_mo_vals(*procurement, bom)) if errors:
raise ProcurementException(errors)
if errors: for company_id, productions_values in productions_values_by_company.items():
raise ProcurementException(errors) # create the MO as SUPERUSER because the current user may not have the rights to do it (mto product launched by a sale for example)
productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(
productions_values)
self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
print(productions.product_id.processing_panel)
# 查出产品的加工面板并对根据面板的数量循环生成工序
for k in (productions.product_id.processing_panel.split(',')):
print(productions.product_id.model_type_id.routing_tmpl_id)
for j in productions.product_id.model_type_id.routing_tmpl_id:
productions._create_workorder()
productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \
(
p.move_dest_ids.procure_method != 'make_to_order' and not p.move_raw_ids and not p.workorder_ids)).action_confirm()
for company_id, productions_values in productions_values_by_company.items(): for production in productions:
# create the MO as SUPERUSER because the current user may not have the rights to do it (mto product launched by a sale for example) origin_production = production.move_dest_ids and production.move_dest_ids[
productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create( 0].raw_material_production_id or False
productions_values)
self.env['stock.move'].sudo().create(productions._get_moves_raw_values())
self.env['stock.move'].sudo().create(productions._get_moves_finished_values())
# 查出产品的加工面板并对根据面板的数量循环生成工序
productions._create_workorder()
productions.filtered(lambda p: (not p.orderpoint_id and p.move_raw_ids) or \
(
p.move_dest_ids.procure_method != 'make_to_order' and not p.move_raw_ids and not p.workorder_ids)).action_confirm()
for production in productions:
origin_production = production.move_dest_ids and production.move_dest_ids[
0].raw_material_production_id or False
orderpoint = production.orderpoint_id orderpoint = production.orderpoint_id
if orderpoint and orderpoint.create_uid.id == SUPERUSER_ID and orderpoint.trigger == 'manual': if orderpoint and orderpoint.create_uid.id == SUPERUSER_ID and orderpoint.trigger == 'manual':
production.message_post( production.message_post(
@@ -57,7 +59,7 @@ def _run_manufacture(self, procurements):
'mail.message_origin_link', 'mail.message_origin_link',
values={'self': production, 'origin': origin_production}, values={'self': production, 'origin': origin_production},
subtype_id=self.env.ref('mail.mt_note').id) subtype_id=self.env.ref('mail.mt_note').id)
return True return True
class ResMrpWorkOrder(models.Model): class ResMrpWorkOrder(models.Model):
@@ -66,16 +68,6 @@ class ResMrpWorkOrder(models.Model):
workcenter_id = fields.Many2one('mrp.workcenter', required=False) workcenter_id = fields.Many2one('mrp.workcenter', required=False)
processing_panel = fields.Char('加工面') processing_panel = fields.Char('加工面')
@api.model_create_multi
def create(self, values):
res = super().create(values)
if self.env.context.get('skip_confirm'):
return res
to_confirm = res.filtered(lambda wo: wo.production_id.state in ("confirmed", "progress", "to_close"))
to_confirm = to_confirm.production_id.workorder_ids
to_confirm._action_confirm()
return res
def _action_confirm(self): def _action_confirm(self):
workorders_by_production = defaultdict(lambda: self.env['mrp.workorder']) workorders_by_production = defaultdict(lambda: self.env['mrp.workorder'])
for workorder in self: for workorder in self:

View File

@@ -42,7 +42,6 @@ class MrpProduction(models.Model):
def _create_workorder(self): def _create_workorder(self):
for production in self: for production in self:
print(production.product_id.model_type_id)
if not production.bom_id or not production.product_id: if not production.bom_id or not production.product_id:
continue continue
workorders_values = [] workorders_values = []