diff --git a/sf_base/__manifest__.py b/sf_base/__manifest__.py
index 77165cde..4a493cd2 100644
--- a/sf_base/__manifest__.py
+++ b/sf_base/__manifest__.py
@@ -10,7 +10,7 @@
""",
'category': 'YZ',
'website': 'https://www.sf.jikimo.com',
- 'depends': ['account', 'base', 'mrp'],
+ 'depends': ['account', 'base', 'mrp', 'sf_bpm_api'],
'data': [
'security/group_security.xml',
'security/ir.model.access.csv',
diff --git a/sf_base/views/menu_view.xml b/sf_base/views/menu_view.xml
index 29dcfa59..e9a5876a 100644
--- a/sf_base/views/menu_view.xml
+++ b/sf_base/views/menu_view.xml
@@ -91,6 +91,14 @@
sequence="1"
action="mrs_processing_technology"/>
+
+
+
@@ -142,5 +151,6 @@
+
\ No newline at end of file
diff --git a/sf_base/views/mrs_common_view.xml b/sf_base/views/mrs_common_view.xml
index b05cd135..a58eed68 100644
--- a/sf_base/views/mrs_common_view.xml
+++ b/sf_base/views/mrs_common_view.xml
@@ -277,38 +277,39 @@
-
-
-
+
+
+
-
-
-
+
+
+
-
-
-
-
+
+
+
+
-
-
-
-
-
-
-
+
+
+
+
+
+
+
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
@@ -345,5 +346,11 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/sf_manufacturing_orders/.DS_Store b/sf_manufacturing_orders/.DS_Store
new file mode 100644
index 00000000..bdbf87a8
Binary files /dev/null and b/sf_manufacturing_orders/.DS_Store differ
diff --git a/sf_manufacturing_orders/__init__.py b/sf_manufacturing_orders/__init__.py
new file mode 100644
index 00000000..0650744f
--- /dev/null
+++ b/sf_manufacturing_orders/__init__.py
@@ -0,0 +1 @@
+from . import models
diff --git a/sf_manufacturing_orders/__manifest__.py b/sf_manufacturing_orders/__manifest__.py
new file mode 100644
index 00000000..9ef495bb
--- /dev/null
+++ b/sf_manufacturing_orders/__manifest__.py
@@ -0,0 +1,24 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+{
+ 'name': '机企猫智能工厂 制造订单',
+ 'version': '1.0',
+ 'summary': '智能工厂制造订单',
+ 'sequence': 1,
+ 'description': """
+
+ """,
+ 'category': '',
+ 'website': 'https://www.sf.jikimo.com',
+ 'depends': ['mrp'],
+ 'data': [
+ 'views/sf_production.xml',
+ ],
+ 'demo': [
+ ],
+ 'qweb': [
+ ],
+ 'installable': True,
+ 'application': False,
+ 'auto_install': False,
+}
diff --git a/sf_manufacturing_orders/models/__init__.py b/sf_manufacturing_orders/models/__init__.py
new file mode 100644
index 00000000..3fb32983
--- /dev/null
+++ b/sf_manufacturing_orders/models/__init__.py
@@ -0,0 +1 @@
+from. import sf_production
diff --git a/sf_manufacturing_orders/models/sf_production.py b/sf_manufacturing_orders/models/sf_production.py
new file mode 100644
index 00000000..5191d791
--- /dev/null
+++ b/sf_manufacturing_orders/models/sf_production.py
@@ -0,0 +1,191 @@
+# -*- coding: utf-8 -*-
+import logging
+from collections import defaultdict, namedtuple
+from odoo.addons.stock.models.stock_rule import ProcurementException
+
+from dateutil.relativedelta import relativedelta
+
+from odoo import SUPERUSER_ID, _, api, fields, models, registry
+from odoo.exceptions import UserError
+from odoo.osv import expression
+from odoo.tools import float_compare, float_is_zero, html_escape
+from odoo.tools.misc import split_every
+
+_logger = logging.getLogger(__name__)
+
+
+class ProductTemplate(models.Model):
+ _inherit = 'product.template'
+ _description = '产品模板'
+
+ single_manufacturing = fields.Boolean(string="单个制造")
+
+
+class ProcurementGroup(models.Model):
+ _inherit = 'procurement.group'
+
+
+class MrpProduction(models.Model):
+ _inherit = 'mrp.production'
+ _description = "制造订单"
+
+ # @api.model
+ # def create(self, values):
+ # n = values
+ # if values['product_qty']== 1.0:
+ # return self.env['mrp.production'].create1(values)
+ # else:
+ # for i in range(int(values.get('product_qty'))):
+ # b = n
+ # b['product_qty'] = 1.0
+ # self.env['mrp.production'].create1(b)
+
+ # @api.model
+ # def create(self, values):
+ # # Remove from `move_finished_ids` the by-product moves and then move `move_byproduct_ids`
+ # # into `move_finished_ids` to avoid duplicate and inconsistency.
+ # if values.get('move_finished_ids', False):
+ # values['move_finished_ids'] = list(
+ # filter(lambda move: move[2]['byproduct_id'] is False, values['move_finished_ids']))
+ # if values.get('move_byproduct_ids', False):
+ # values['move_finished_ids'] = values.get('move_finished_ids', []) + values['move_byproduct_ids']
+ # del values['move_byproduct_ids']
+ # if not values.get('name', False) or values['name'] == _('New'):
+ # picking_type_id = values.get('picking_type_id') or self._get_default_picking_type()
+ # picking_type_id = self.env['stock.picking.type'].browse(picking_type_id)
+ # if picking_type_id:
+ # values['name'] = picking_type_id.sequence_id.next_by_id()
+ # else:
+ # values['name'] = self.env['ir.sequence'].next_by_code('mrp.production') or _('New')
+ # if not values.get('procurement_group_id'):
+ # procurement_group_vals = self._prepare_procurement_group_vals(values)
+ # values['procurement_group_id'] = self.env["procurement.group"].create(procurement_group_vals).id
+ # production = super(MrpProduction, self).create(values)
+ # (production.move_raw_ids | production.move_finished_ids).write({
+ # 'group_id': production.procurement_group_id.id,
+ # 'origin': production.name
+ # })
+ # production.move_raw_ids.write({'date': production.date_planned_start})
+ # production.move_finished_ids.write({'date': production.date_planned_finished})
+ # # Trigger move_raw creation when importing a file
+ # if 'import_file' in self.env.context:
+ # production._onchange_move_raw()
+ # production._onchange_move_finished()
+ # return production
+
+
+class StockRule(models.Model):
+ _inherit = 'stock.rule'
+
+ @api.model
+ 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)
+
+ product = self.env['product.template'].search(
+ ["&", ("name", '=', procurement.product_id.display_name), ('single_manufacturing', '!=', False)])
+ if not product:
+ productions_values_by_company[procurement.company_id.id].append(
+ rule._prepare_mo_vals1(*procurement, bom))
+ else:
+ orders_vals = rule._prepare_mo_vals(*procurement, bom)
+
+ if isinstance(orders_vals, list):
+ for vals in orders_vals:
+ productions_values_by_company[procurement.company_id.id].append(vals)
+ else:
+ productions_values_by_company[procurement.company_id.id].append(orders_vals)
+
+ if errors:
+ raise ProcurementException(errors)
+
+ for company_id, productions_values in productions_values_by_company.items():
+ # 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())
+ 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
+ if orderpoint and orderpoint.create_uid.id == SUPERUSER_ID and orderpoint.trigger == 'manual':
+ production.message_post(
+ body=_('This production order has been created from Replenishment Report.'),
+ message_type='comment',
+ subtype_xmlid='mail.mt_note')
+ elif orderpoint:
+ production.message_post_with_view(
+ 'mail.message_origin_link',
+ values={'self': production, 'origin': orderpoint},
+ subtype_id=self.env.ref('mail.mt_note').id)
+ elif origin_production:
+ production.message_post_with_view(
+ 'mail.message_origin_link',
+ values={'self': production, 'origin': origin_production},
+ subtype_id=self.env.ref('mail.mt_note').id)
+ return True
+
+ def _prepare_mo_vals1(self, product_id, product_qty, product_uom, location_id, name, origin, company_id, values,
+ bom):
+ date_planned = self._get_date_planned(product_id, company_id, values)
+ date_deadline = values.get('date_deadline') or date_planned + relativedelta(
+ days=company_id.manufacturing_lead) + relativedelta(days=product_id.produce_delay)
+ mo_values = {
+ 'origin': origin,
+ 'product_id': product_id.id,
+ 'product_description_variants': values.get('product_description_variants'),
+ 'product_qty': product_qty,
+ 'product_uom_id': product_uom.id,
+ 'location_src_id': self.location_src_id.id or self.picking_type_id.default_location_src_id.id or location_id.id,
+ 'location_dest_id': location_id.id,
+ 'bom_id': bom.id,
+ 'date_deadline': date_deadline,
+ 'date_planned_start': date_planned,
+ 'date_planned_finished': fields.Datetime.from_string(values['date_planned']),
+ 'procurement_group_id': False,
+ 'propagate_cancel': self.propagate_cancel,
+ 'orderpoint_id': values.get('orderpoint_id', False) and values.get('orderpoint_id').id,
+ 'picking_type_id': self.picking_type_id.id or values['warehouse_id'].manu_type_id.id,
+ 'company_id': company_id.id,
+ 'move_dest_ids': values.get('move_dest_ids') and [(4, x.id) for x in values['move_dest_ids']] or False,
+ 'user_id': False,
+ }
+ # Use the procurement group created in _run_pull mrp override
+ # Preserve the origin from the original stock move, if available
+ if location_id.warehouse_id.manufacture_steps == 'pbm_sam' and values.get('move_dest_ids') and values.get(
+ 'group_id') and values['move_dest_ids'][0].origin != values['group_id'].name:
+ origin = values['move_dest_ids'][0].origin
+ mo_values.update({
+ 'name': values['group_id'].name,
+ 'procurement_group_id': values['group_id'].id,
+ 'origin': origin,
+ })
+ return mo_values
+
+ def _prepare_mo_vals(self, product_id, product_qty, product_uom, location_id, name, origin, company_id, values,
+ bom):
+
+ mo_lists = []
+ for num in range(1, int(product_qty) + 1):
+ vals = super(StockRule, self)._prepare_mo_vals(product_id, 1.0, product_uom, location_id, name, origin,
+ company_id, values,
+ bom)
+ vals.update({
+ # 'name': values['group_id'].name,
+ 'procurement_group_id': values['group_id'].id,
+ # 'origin': origin,
+ })
+ mo_lists.append(vals)
+
+ return mo_lists
diff --git a/sf_manufacturing_orders/views/sf_production.xml b/sf_manufacturing_orders/views/sf_production.xml
new file mode 100644
index 00000000..5968bfb6
--- /dev/null
+++ b/sf_manufacturing_orders/views/sf_production.xml
@@ -0,0 +1,39 @@
+
+
+
+
+ product.template.stock.property.form.inherit
+ product.template
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ stock.group_stock_user,product.group_stock_packaging
+
+
+
+
+
\ No newline at end of file