diff --git a/jikimo_sale_multiple_supply_methods/__init__.py b/jikimo_sale_multiple_supply_methods/__init__.py new file mode 100644 index 00000000..74eea1d2 --- /dev/null +++ b/jikimo_sale_multiple_supply_methods/__init__.py @@ -0,0 +1,143 @@ +# -*- coding: utf-8 -*- +from . import models +from . import controllers + +from odoo import api, SUPERUSER_ID + +def _data_install(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + # 获取所有需要设置的产品模板 + env.ref('jikimo_sale_multiple_supply_methods.product_template_purchase').product_variant_id.write({'active': False, 'is_bfm': True}) + env.ref('jikimo_sale_multiple_supply_methods.product_template_manual_processing').product_variant_id.write({'active': False, 'single_manufacturing': True, 'is_bfm': True}) + env.ref('jikimo_sale_multiple_supply_methods.product_template_default').product_variant_id.write({'active': False, 'is_bfm': True}) + env.ref('jikimo_sale_multiple_supply_methods.product_template_embryo_customer_provided').product_variant_id.write({'active': False}) + env.ref('jikimo_sale_multiple_supply_methods.product_template_outsourcing').product_variant_id.write({'active': False, 'is_bfm': True}) + env.ref('sf_dlm.product_embryo_sf_self_machining').product_tmpl_id.write({'categ_type': '坯料'}) + env.ref('sf_dlm.product_template_sf').product_tmpl_id.write({'categ_type': '成品'}) + env.ref('sf_dlm.product_embryo_sf_outsource').product_tmpl_id.write({'categ_type': '坯料'}) + env.ref('sf_dlm.product_embryo_sf_purchase').product_tmpl_id.write({'categ_type': '坯料'}) + + # 为三步制造增加规则 + warehouse = env['stock.warehouse'].search([('company_id', '=', env.company.id)], limit=1) + product_route_id = warehouse.pbm_route_id + # 创建规则:原料存货区 -> 制造前, 坯料存货区 -> 制造前, 制造后 -> 坯料存货区, 制造后 -> 成品存货区 + raw_material_location_id = env['stock.location'].search([('name', '=', '坯料存货区')], limit=1) + picking_type_production = warehouse.pbm_type_id + picking_type_stock = warehouse.sam_type_id + material_location_id = env['stock.location'].search([('name', '=', '原料存货区')], limit=1) + # 为mto增加规则 + mto_route_id = env.ref('stock.route_warehouse0_mto') + # 创建规则:原料存货区 -> 外包位置, 坯料存货区 -> 外包位置 + subcontracting_location_id = env.company.subcontracting_location_id + picking_type_subcontracting = warehouse.subcontracting_resupply_type_id + # 为补给外包商增加规则 + resupply_route_id = warehouse.subcontracting_route_id + + rules_data = [ + { + 'name': 'WH: 原料存货区 → 制造前', + 'location_src_id': material_location_id.id, + 'location_dest_id': warehouse.pbm_loc_id.id, + 'route_id': product_route_id.id, + 'picking_type_id': picking_type_production.id, + 'action': 'pull', + 'sequence': 20, + 'warehouse_id': warehouse.id, + 'procure_method': 'mts_else_mto', + }, + { + 'name': 'WH: 坯料存货区 → 制造前', + 'location_src_id': raw_material_location_id.id, + 'location_dest_id': warehouse.pbm_loc_id.id, + 'route_id': product_route_id.id, + 'picking_type_id': picking_type_production.id, + 'action': 'pull', + 'sequence': 21, + 'warehouse_id': warehouse.id, + 'procure_method': 'mts_else_mto', + }, + { + 'name': 'WH: 制造后 → 坯料存货区', + 'location_src_id': warehouse.sam_loc_id.id, + 'location_dest_id': raw_material_location_id.id, + 'route_id': product_route_id.id, + 'picking_type_id': picking_type_stock.id, + 'action': 'push', + 'sequence': 23, + }, + { + 'name': 'WH: 制造后 → 成品存货区', + 'location_src_id': warehouse.sam_loc_id.id, + 'location_dest_id': env['stock.location'].search([('name', '=', '成品存货区')], limit=1).id, + 'route_id': product_route_id.id, + 'picking_type_id': picking_type_stock.id, + 'action': 'push', + 'sequence': 24, + }, + { + 'name': 'WH: 原料存货区 → 外包位置 (MTO)', + 'location_src_id': material_location_id.id, + 'location_dest_id': subcontracting_location_id.id, + 'route_id': mto_route_id.id, + 'picking_type_id': picking_type_subcontracting.id, + 'action': 'pull', + 'sequence': 24, + 'warehouse_id': warehouse.id, + 'procure_method': 'mts_else_mto', + }, + { + 'name': 'WH: 坯料存货区 → 外包位置 (MTO)', + 'location_src_id': raw_material_location_id.id, + 'location_dest_id': subcontracting_location_id.id, + 'route_id': mto_route_id.id, + 'picking_type_id': picking_type_subcontracting.id, + 'action': 'pull', + 'sequence': 25, + 'warehouse_id': warehouse.id, + 'procure_method': 'mts_else_mto', + }, + { + 'name': 'WH: 坯料存货区 → 外包位置', + 'location_src_id': raw_material_location_id.id, + 'location_dest_id': subcontracting_location_id.id, + 'route_id': resupply_route_id.id, + 'picking_type_id': picking_type_subcontracting.id, + 'action': 'pull', + 'sequence': 26, + 'warehouse_id': warehouse.id, + 'procure_method': 'make_to_stock', + } + ] + # 遍历每个规则数据,执行创建或更新操作 + for rule_data in rules_data: + _create_or_update_stock_rule(env, rule_data) + +def _create_or_update_stock_rule(env, rule_data): + # 尝试查找现有的 stock.rule + existing_rule = env['stock.rule'].search([ + ('name', '=', rule_data['name']), + ('route_id', '=', rule_data.get('route_id')) + ], limit=1) + + if existing_rule: + # 如果存在,更新现有记录 + existing_rule.write(rule_data) + else: + # 如果不存在,创建新记录 + env['stock.rule'].create(rule_data) + +def _data_uninstall(cr, registry): + env = api.Environment(cr, SUPERUSER_ID, {}) + warehouse = env['stock.warehouse'].search([('company_id', '=', env.company.id)], limit=1) + product_route_id = warehouse.pbm_route_id + resupply_route_id = warehouse.subcontracting_route_id + mto_route_id = env.ref('stock.route_warehouse0_mto') + # Fail unlink means that the route is used somewhere (e.g. route_id on stock.rule). In this case + # we don't try to do anything. + try: + with env.cr.savepoint(): + env['stock.rule'].search([('name', 'in', ('WH: 原料存货区 → 制造前', 'WH: 坯料存货区 → 制造前', 'WH: 制造后 → 坯料存货区', 'WH: 制造后 → 成品存货区')), ('route_id', '=', product_route_id.id)]).unlink() + env['stock.rule'].search([('name', 'in', ('WH: 原料存货区 → 外包位置 (MTO)', 'WH: 坯料存货区 → 外包位置 (MTO)')), ('route_id', '=', mto_route_id.id)]).unlink() + env['stock.rule'].search([('name', '=', 'WH: 坯料存货区 → 外包位置'), ('route_id', '=', resupply_route_id.id)]).unlink() + except: + pass \ No newline at end of file diff --git a/jikimo_sale_multiple_supply_methods/__manifest__.py b/jikimo_sale_multiple_supply_methods/__manifest__.py new file mode 100644 index 00000000..a7d39ac7 --- /dev/null +++ b/jikimo_sale_multiple_supply_methods/__manifest__.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +{ + 'name': '机企猫 多供货方式', + 'version': '16.0.1.0.0', + 'summary': """ 报价单提供(自动化产线加工/人工线下加工/外购/委外加工)多种供货方式选择 """, + 'author': 'fox', + 'website': '', + 'category': '', + 'depends': ['sf_dlm', 'sale_stock', 'sf_sale'], + "data": [ + 'security/ir.model.access.csv', + 'data/stock_routes.xml', + 'data/product_data.xml', + 'views/sale_order_views.xml', + # 'views/product_product_views.xml', + ],'assets': { + # 'web.assets_backend': [ + # 'jikimo_sale_multiple_supply_methods/static/src/**/*' + # ], + }, + 'post_init_hook': '_data_install', + 'uninstall_hook': '_data_uninstall', + 'application': True, + 'installable': True, + 'auto_install': False, + 'license': 'LGPL-3', +} diff --git a/jikimo_sale_multiple_supply_methods/controllers/__init__.py b/jikimo_sale_multiple_supply_methods/controllers/__init__.py new file mode 100644 index 00000000..cd4d6a8b --- /dev/null +++ b/jikimo_sale_multiple_supply_methods/controllers/__init__.py @@ -0,0 +1,2 @@ +# -*- coding: utf-8 -*- +from . import main \ No newline at end of file diff --git a/jikimo_sale_multiple_supply_methods/controllers/main.py b/jikimo_sale_multiple_supply_methods/controllers/main.py new file mode 100644 index 00000000..b5a25749 --- /dev/null +++ b/jikimo_sale_multiple_supply_methods/controllers/main.py @@ -0,0 +1,50 @@ +import logging +import json +from odoo import http +from odoo.http import request +from odoo.addons.sf_bf_connect.controllers.controllers import Sf_Bf_Connect + +_logger = logging.getLogger(__name__) + +class JikimoSaleRoutePicking(Sf_Bf_Connect): + + @http.route('/api/bfm_process_order/list', type='http', auth='sf_token', methods=['GET', 'POST'], csrf=False, + cors="*") + def get_bfm_process_order_list(self, **kw): + """ + 接收业务平台加工订单分配工厂时传送来的订单数据并生成销售订单和产品及坯料 + :param kw: + :return: + """ + res = {'status': 1, 'factory_order_no': ''} + # _logger.info('get_bfm_process_order_list:%s' % kw['order_number']) + try: + product_id = request.env.ref('jikimo_sale_multiple_supply_methods.product_template_default').with_context(active_test=False).sudo().product_variant_id + _logger.info('product_id:%s' % product_id) + company_id = request.env.ref('base.main_company').sudo() + bfm_process_order_list = json.loads(kw['bfm_process_order_list']) + order_id = request.env['sale.order'].with_user(request.env.ref("base.user_admin")).sale_order_create( + company_id, kw['delivery_name'], kw['delivery_telephone'], kw['delivery_address'], + kw['delivery_end_date'], kw['payments_way'], kw['pay_way'], state='draft') + i = 1 + # 给sale_order的default_code字段赋值 + # aa = request.env['sale.order'].sudo().search([('name', '=', order_id.name)]) + # _logger.info('get_bfm_process_or===================================:%s' % order_id.name) + order_id.default_code = kw['order_number'] + if kw.get('logistics_way'): + order_id.logistics_way = kw['logistics_way'] + for item in bfm_process_order_list: + if item.get('embryo_redundancy_id'): + item['embryo_redundancy'] = request.env['sf.embryo.redundancy'].sudo().search([('code', '=', item['embryo_redundancy_id'])], limit=1) + item['embryo_redundancy_id'] = item['embryo_redundancy'].id + product = request.env['product.template'].sudo().product_create(product_id, item, order_id, + kw['order_number'], i) + order_id.with_user(request.env.ref("base.user_admin")).sale_order_create_line(product, item) + i += 1 + res['factory_order_no'] = order_id.name + except Exception as e: + _logger.info('get_bfm_process_order_list error:%s' % e) + res['status'] = -1 + res['message'] = '工厂创建销售订单和产品失败,请联系管理员' + request.cr.rollback() + return json.JSONEncoder().encode(res) diff --git a/jikimo_sale_multiple_supply_methods/data/product_data.xml b/jikimo_sale_multiple_supply_methods/data/product_data.xml new file mode 100644 index 00000000..b63da7ea --- /dev/null +++ b/jikimo_sale_multiple_supply_methods/data/product_data.xml @@ -0,0 +1,98 @@ + + + + + 人工线下加工模板 + + + + delivery + product + false + + + + true + serial + + true + + + + 成品外购模板 + + + + serial + product + + + + + + + + 成品委外加工模板 + + + + serial + product + + + + + + + + 成品初始化模板 + + + + serial + product + + + + + + + + + + + + + 坯料客供料模板 + + + + false + serial + product + + + + + + + + + true + + + + + + + + + + + \ No newline at end of file diff --git a/jikimo_sale_multiple_supply_methods/data/stock_routes.xml b/jikimo_sale_multiple_supply_methods/data/stock_routes.xml new file mode 100644 index 00000000..de4c2106 --- /dev/null +++ b/jikimo_sale_multiple_supply_methods/data/stock_routes.xml @@ -0,0 +1,32 @@ + + + + + 带料加工 + true + true + + 16 + + + + 客供料入库 + incoming + true + + DL + + + + + + + 带料收货 + + + + + pull + + + \ No newline at end of file diff --git a/jikimo_sale_multiple_supply_methods/models/__init__.py b/jikimo_sale_multiple_supply_methods/models/__init__.py new file mode 100644 index 00000000..6629e86d --- /dev/null +++ b/jikimo_sale_multiple_supply_methods/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +from . import product_template +from . import sale_order +from . import mrp_bom diff --git a/jikimo_sale_multiple_supply_methods/models/mrp_bom.py b/jikimo_sale_multiple_supply_methods/models/mrp_bom.py new file mode 100644 index 00000000..2528d0a4 --- /dev/null +++ b/jikimo_sale_multiple_supply_methods/models/mrp_bom.py @@ -0,0 +1,13 @@ +from odoo import models, fields + +class MrpBom(models.Model): + _inherit = 'mrp.bom' + + # 业务平台分配工厂后在智能工厂先创建销售订单再创建该产品后再次进行创建bom + def bom_create(self, product, bom_type, product_type): + bom_id = super(MrpBom, self).bom_create(product, bom_type, product_type) + + # 成品的供应商从模板中获取 + if product_type == 'product': + bom_id.subcontractor_id = product.product_tmpl_id.seller_ids.partner_id.id + return bom_id diff --git a/jikimo_sale_multiple_supply_methods/models/product_template.py b/jikimo_sale_multiple_supply_methods/models/product_template.py new file mode 100644 index 00000000..c7dfa1ab --- /dev/null +++ b/jikimo_sale_multiple_supply_methods/models/product_template.py @@ -0,0 +1,32 @@ +from odoo import models, fields, api + +class ProductTemplate(models.Model): + _inherit = 'product.template' + + is_manual_processing = fields.Boolean(string='人工线下加工') + is_customer_provided = fields.Boolean(string='客供料') + + def product_create(self, product_id, item, order_id, order_number, i): + product_id = super(ProductTemplate, self).product_create(product_id, item, order_id, order_number, i) + product_id.product_tmpl_id.is_customer_provided = True if item['embryo_redundancy_id'] else False + return product_id + + + def copy_template(self, product_template_id): + if not isinstance(product_template_id, ProductTemplate): + raise ValueError('%s必须是ProductTemplate类型' % product_template_id) + + self.route_ids = product_template_id.route_ids + self.categ_id = product_template_id.categ_id + self.invoice_policy = product_template_id.invoice_policy + self.detailed_type = product_template_id.detailed_type + self.purchase_ok = product_template_id.purchase_ok + self.uom_id = product_template_id.uom_id + self.uom_po_id = product_template_id.uom_po_id + self.company_id = product_template_id.company_id + self.single_manufacturing = product_template_id.single_manufacturing + self.tracking = product_template_id.tracking + self.is_bfm = product_template_id.is_bfm + self.is_manual_processing = product_template_id.is_manual_processing + # 复制 seller_ids + self.seller_ids = [(0, 0, {'partner_id': seller.partner_id.id, 'delay': 1.0}) for seller in product_template_id.seller_ids] diff --git a/jikimo_sale_multiple_supply_methods/models/quick_easy_order.py b/jikimo_sale_multiple_supply_methods/models/quick_easy_order.py new file mode 100644 index 00000000..89d3a6d8 --- /dev/null +++ b/jikimo_sale_multiple_supply_methods/models/quick_easy_order.py @@ -0,0 +1,71 @@ +from datetime import datetime +from odoo import models + +import logging +import base64 +import hashlib + +_logger = logging.getLogger(__name__) + + +class QuickEasyOrder(models.Model): + _inherit = 'quick.easy.order' + + def distribute_to_factory(self, obj): + """ + 多供货方式,重写派单到工厂 + :return: + """ + try: + _logger.info('---------派单到工厂-------') + res = {'bfm_process_order_list': []} + for item in obj: + attachment = item.upload_model_file[0] + base64_data = base64.b64encode(attachment.datas) + base64_datas = base64_data.decode('utf-8') + barcode = hashlib.sha1(base64_datas.encode('utf-8')).hexdigest() + # logging.info('model_file-size: %s' % len(item.model_file)) + res['bfm_process_order_list'].append({ + 'model_long': item.model_length, + 'model_width': item.model_width, + 'model_height': item.model_height, + 'model_volume': item.model_volume, + 'model_machining_precision': item.machining_precision, + 'model_name': attachment.name, + 'model_data': base64_datas, + 'model_file': base64.b64encode(item.model_file).decode('utf-8'), + 'texture_code': item.material_id.materials_no, + 'texture_type_code': item.material_model_id.materials_no, + # 'surface_process_code': self.env['jikimo.surface.process']._json_surface_process_code(item), + 'process_parameters_code': self.env[ + 'sf.production.process.parameter']._json_production_process_item_code( + item), + 'price': item.price, + 'number': item.quantity, + 'total_amount': item.price, + 'remark': '', + 'manual_quotation': True, + 'barcode': barcode, + 'part_number': item.part_drawing_number, + 'machining_drawings_name': '', + 'quality_standard_name': '', + 'machining_drawings_mimetype': '', + 'quality_standard_mimetype': '', + 'machining_drawings': item.machining_drawings, + 'quality_standard': '', + 'part_name': '', + }) + company_id = self.env.ref('base.main_company').sudo() + product_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_default').sudo().with_context(active_test=False).product_variant_id + # user_id = request.env.ref('base.user_admin').sudo() + order_id = self.env['sale.order'].sale_order_create(company_id, 'XXXXX', 'XXXXX', 'XXXXX', + str(datetime.now()), '现结', '支付宝', state='draft') + order_id.default_code = obj.name + i = 1 + for item in res['bfm_process_order_list']: + product = self.env['product.template'].sudo().product_create(product_id, item, order_id, + obj.name, i) + order_id.with_user(self.env.ref("base.user_admin")).sale_order_create_line(product, item) + return order_id + except Exception as e: + return UserError('工厂创建销售订单和产品失败,请联系管理员') diff --git a/jikimo_sale_multiple_supply_methods/models/sale_order.py b/jikimo_sale_multiple_supply_methods/models/sale_order.py new file mode 100644 index 00000000..a1920a50 --- /dev/null +++ b/jikimo_sale_multiple_supply_methods/models/sale_order.py @@ -0,0 +1,157 @@ +import logging +import json +from odoo import models, fields, api +from odoo.exceptions import UserError + +_logger = logging.getLogger(__name__) + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + state = fields.Selection([ + ('draft', "报价"), + ('sent', "报价已发送"), + ('supply method', "供货方式待确认"), + ('sale', "销售订单"), + ('done', "已锁定"), + ('cancel', "已取消"), + ]) + + def confirm_to_supply_method(self): + self.state = 'supply method' + + def action_confirm(self): + # 判断是否所有产品都选择了供货方式 + filter_line = self.order_line.filtered(lambda line: not line.supply_method) + if filter_line: + raise UserError('当前订单内(%s)产品未选择路线,请选择后重试' % ','.join(filter_line.mapped('product_id.name'))) + + for line in self.order_line: + bom_type = '' + # 根据供货方式修改成品模板 + if line.supply_method == 'automation': + bom_type = 'normal' + product_template_id = self.env.ref('sf_dlm.product_template_sf').sudo().product_tmpl_id + elif line.supply_method == 'outsourcing': + bom_type = 'subcontract' + product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_outsourcing').sudo() + elif line.supply_method == 'purchase': + product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_purchase').sudo() + elif line.supply_method == 'manual': + bom_type = 'normal' + product_template_id = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_manual_processing').sudo() + + # 复制成品模板上的属性 + line.product_id.product_tmpl_id.copy_template(product_template_id) + + order_id = self + product = line.product_id + # 拼接方法需要的item结构 + item = { + 'texture_code': product.materials_id.materials_no, + 'texture_type_code': product.materials_type_id.materials_no, + 'model_long': product.length, + 'model_width': product.width, + 'model_height': product.height, + 'price': product.list_price, + 'embryo_redundancy_id': line.embryo_redundancy_id, + } + # 获取成品名结尾-n的n + product_seria = int(product.name.split('-')[-1]) + # 成品供货方式为采购则不生成bom + if line.supply_method != 'purchase': + bom_data = self.env['mrp.bom'].with_user(self.env.ref("base.user_admin")).get_bom(product) + _logger.info('bom_data:%s' % bom_data) + if bom_data: + bom = self.env['mrp.bom'].with_user(self.env.ref("base.user_admin")).bom_create(product, 'normal', False) + bom.with_user(self.env.ref("base.user_admin")).bom_create_line_has(bom_data) + else: + # 当成品上带有客供料选项时,生成坯料时选择“客供料”路线 + if line.embryo_redundancy_id: + # 将成品模板的内容复制到成品上 + customer_provided_embryo = self.env.ref('jikimo_sale_multiple_supply_methods.product_template_embryo_customer_provided').sudo() + # 创建坯料,客供料的批量不需要创建bom + material_customer_provided_embryo = self.env['product.template'].sudo().no_bom_product_create( + customer_provided_embryo.with_context(active_test=False).product_variant_id, + item, + order_id, 'material_customer_provided', product_seria, product) + # 成品配置bom + product_bom_material_customer_provided = self.env['mrp.bom'].with_user( + self.env.ref("base.user_admin")).bom_create( + product, bom_type, 'product') + product_bom_material_customer_provided.with_user(self.env.ref("base.user_admin")).bom_create_line_has( + material_customer_provided_embryo) + elif line.product_id.materials_type_id.gain_way == '自加工': + self_machining_id = self.env.ref('sf_dlm.product_embryo_sf_self_machining').sudo() + # 创建坯料 + self_machining_embryo = self.env['product.template'].sudo().no_bom_product_create( + self_machining_id, + item, + order_id, 'self_machining', product_seria, product) + # 创建坯料的bom + self_machining_bom = self.env['mrp.bom'].with_user( + self.env.ref("base.user_admin")).bom_create( + self_machining_embryo, 'normal', False) + # 创建坯料里bom的组件 + self_machining_bom_line = self_machining_bom.with_user( + self.env.ref("base.user_admin")).bom_create_line( + self_machining_embryo) + if not self_machining_bom_line: + raise UserError('该订单模型的材料型号暂未有原材料,请先配置再进行分配') + # 产品配置bom + product_bom_self_machining = self.env['mrp.bom'].with_user( + self.env.ref("base.user_admin")).bom_create( + product, bom_type, 'product') + product_bom_self_machining.with_user(self.env.ref("base.user_admin")).bom_create_line_has( + self_machining_embryo) + elif line.product_id.materials_type_id.gain_way == '外协': + outsource_id = self.env.ref('sf_dlm.product_embryo_sf_outsource').sudo() + # 创建坯料 + outsource_embryo = self.env['product.template'].sudo().no_bom_product_create(outsource_id, + item, + order_id, + 'subcontract', + product_seria, product) + if outsource_embryo == -3: + raise UserError('该订单模型的材料型号暂未设置获取方式和供应商,请先配置再进行分配') + # 创建坯料的bom + outsource_bom = self.env['mrp.bom'].with_user(self.env.ref("base.user_admin")).bom_create( + outsource_embryo, + 'subcontract', True) + # 创建坯料的bom的组件 + outsource_bom_line = outsource_bom.with_user( + self.env.ref("base.user_admin")).bom_create_line(outsource_embryo) + if not outsource_bom_line: + raise UserError('该订单模型的材料型号暂未有原材料,请先配置再进行分配') + # 产品配置bom + product_bom_outsource = self.env['mrp.bom'].with_user( + self.env.ref("base.user_admin")).bom_create(product, bom_type, 'product') + product_bom_outsource.with_user(self.env.ref("base.user_admin")).bom_create_line_has( + outsource_embryo) + elif line.product_id.materials_type_id.gain_way == '采购': + purchase_id = self.env.ref('sf_dlm.product_embryo_sf_purchase').sudo() + purchase_embryo = self.env['product.template'].sudo().no_bom_product_create(purchase_id, + item, + order_id, + 'purchase', product_seria, + product) + if purchase_embryo == -3: + raise UserError('该订单模型的材料型号暂未设置获取方式和供应商,请先配置再进行分配') + else: + # 产品配置bom + product_bom_purchase = self.env['mrp.bom'].with_user( + self.env.ref("base.user_admin")).bom_create(product, bom_type, 'product') + product_bom_purchase.with_user(self.env.ref("base.user_admin")).bom_create_line_has( + purchase_embryo) + return super(SaleOrder, self).action_confirm() + +class SaleOrderLine(models.Model): + _inherit = 'sale.order.line' + + # 供货方式 + supply_method = fields.Selection([ + ('automation', "自动化产线加工"), + ('manual', "人工线下加工"), + ('purchase', "外购"), + ('outsourcing', "委外加工"), + ], string='供货方式') diff --git a/jikimo_sale_multiple_supply_methods/security/ir.model.access.csv b/jikimo_sale_multiple_supply_methods/security/ir.model.access.csv new file mode 100644 index 00000000..3b276af9 --- /dev/null +++ b/jikimo_sale_multiple_supply_methods/security/ir.model.access.csv @@ -0,0 +1,8 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_sale_order_group_production_engineer,sale.order_group_production_engineer,sale.model_sale_order,sf_base.group_production_engineer,1,1,0,0 +access_sale_order_line_group_production_engineer,sale_order_line_group_production_engineer,sale.model_sale_order_line,sf_base.group_production_engineer,1,1,0,0 +access_product_product_group_production_engineer,product_product_group_production_engineer,product.model_product_product,sf_base.group_production_engineer,1,0,0,0 +access_product_template_group_production_engineer,product_template_group_production_engineer,product.model_product_template,sf_base.group_production_engineer,1,0,0,0 +access_stock_picking_group_production_engineer,stock_picking_group_production_engineer,stock.model_stock_picking,sf_base.group_production_engineer,1,0,0,0 +access_stock_move_group_production_engineer,stock_move_group_production_engineer,stock.model_stock_move,sf_base.group_production_engineer,1,0,0,0 +access_mrp_bom_group_production_engineer,mrp_bom_group_production_engineer,mrp.model_mrp_bom,sf_base.group_production_engineer,1,0,0,0 \ No newline at end of file diff --git a/jikimo_sale_multiple_supply_methods/views/product_product_views.xml b/jikimo_sale_multiple_supply_methods/views/product_product_views.xml new file mode 100644 index 00000000..2c14d2b5 --- /dev/null +++ b/jikimo_sale_multiple_supply_methods/views/product_product_views.xml @@ -0,0 +1,16 @@ + + + + + view.product.template.form.inherit.sf + product.template + + + + + + + + + + \ No newline at end of file diff --git a/jikimo_sale_multiple_supply_methods/views/sale_order_views.xml b/jikimo_sale_multiple_supply_methods/views/sale_order_views.xml new file mode 100644 index 00000000..8b1a85d0 --- /dev/null +++ b/jikimo_sale_multiple_supply_methods/views/sale_order_views.xml @@ -0,0 +1,108 @@ + + + + view.sale.order.form.inherit.sf + + sale.order + + + + + + + + + + view.sale.order.form.inherit.supply.method + + sale.order + + + {'invisible': [('state', '!=', 'draft')]} + confirm_to_supply_method + + + + + + + + + @@ -517,8 +560,9 @@ - diff --git a/sf_manufacturing/views/mrp_routing_workcenter_view.xml b/sf_manufacturing/views/mrp_routing_workcenter_view.xml index eada92d9..ddb9558c 100644 --- a/sf_manufacturing/views/mrp_routing_workcenter_view.xml +++ b/sf_manufacturing/views/mrp_routing_workcenter_view.xml @@ -16,6 +16,7 @@ + diff --git a/sf_manufacturing/views/mrp_workorder_view.xml b/sf_manufacturing/views/mrp_workorder_view.xml index bb06fa04..bbda259c 100644 --- a/sf_manufacturing/views/mrp_workorder_view.xml +++ b/sf_manufacturing/views/mrp_workorder_view.xml @@ -32,8 +32,10 @@ - + @@ -248,7 +250,7 @@ - @@ -257,11 +259,12 @@ -
@@ -281,6 +284,7 @@