From 912847ae33135bc76e64312f524905e6a26f36b9 Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Tue, 24 Jun 2025 14:32:21 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E9=9C=80=E6=B1=82=20=20=20=E8=B0=83?= =?UTF-8?q?=E6=8B=A8=E5=8D=95=E5=85=B3=E8=81=94=E6=A0=A1=E9=AA=8C=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=AE=8C=E6=88=90=E8=B4=A8=E9=87=8F=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=8F=AF=E5=85=88=E6=8E=92=E9=99=A4=E6=AC=A0?= =?UTF-8?q?=E5=8D=95=E9=87=8F=E5=90=8E=E5=86=8D=E6=A0=A1=E9=AA=8C=20=20?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_quality/models/stock.py | 181 ++++++++++++++++++++++++++++++------- 1 file changed, 146 insertions(+), 35 deletions(-) diff --git a/sf_quality/models/stock.py b/sf_quality/models/stock.py index add80f8a..3a68ea30 100644 --- a/sf_quality/models/stock.py +++ b/sf_quality/models/stock.py @@ -1,11 +1,41 @@ +import logging + from odoo import api, models +from odoo.exceptions import ValidationError, UserError class StockPicking(models.Model): _inherit = 'stock.picking' + def _compute_check(self): + super()._compute_check() + for picking in self: + picking_to_quality = picking.get_picking_to_quality() + if not picking_to_quality: + picking.quality_check_todo = False + break + else: + need_quality_line = picking.get_need_quality_line(picking_to_quality) + if not need_quality_line or all(not line.get('need_done_check_ids') for line in need_quality_line): + picking.quality_check_todo = False + + def check_quality(self): + self.ensure_one() + # checkable_products = self.mapped('move_line_ids').mapped('product_id') + # checks = self.check_ids.filtered(lambda check: check.quality_state == 'none' and ( + # check.product_id in checkable_products or check.measure_on == 'operation')) + checks = self.env['quality.check'] + picking_to_quality = self._get_picking_to_quality() + need_quality_line = self.get_need_quality_line(picking_to_quality) + if need_quality_line and any(line.get('need_done_check_ids') for line in need_quality_line): + for item in need_quality_line: + checks += item.get('need_done_check_ids') + if checks: + return checks.action_open_quality_check_wizard() + return False + def button_validate(self): - """ + """= 出厂检验报告上传 """ @@ -17,43 +47,124 @@ class StockPicking(models.Model): if not out_quality_check.is_factory_report_uploaded: if out_quality_check and self.state == 'assigned': out_quality_check.upload_factory_report() + quality_action = self.pinking_checkout_quality() + if quality_action: + return quality_action + res = super(StockPicking, self).button_validate() + return res + def pinking_checkout_quality(self): """ 调拨单若关联了质量检查单,验证调拨单时,应校验是否有不合格品,若存在,应弹窗提示: “警告:存在不合格产品XXXX n 件、YYYYY m件,继续调拨请点“确认”,否则请取消?” """ - context = self.env.context - if not context.get('again_validate') and self.quality_check_ids.filtered(lambda qc: qc.quality_state == 'fail'): - # 回滚事务,为二次确认/取消做准备 - self.env.cr.rollback() - quality_check_ids = self.quality_check_ids.filtered(lambda qc: qc.quality_state == 'fail') - product_list = list(set([quality_check_id.product_id for quality_check_id in quality_check_ids])) - fail_check_text = '' - for product_id in product_list: - check_ids = quality_check_ids.filtered(lambda qc: qc.product_id == product_id) - if all(check_id.measure_on == 'move_line' for check_id in check_ids): - number = sum(check_ids.mapped('qty_line')) - else: - number = sum(self.move_ids_without_package.filtered( - lambda ml: ml.product_id == product_id).mapped('quantity_done')) - if number == 0: - number = sum(self.move_ids_without_package.filtered( - lambda ml: ml.product_id == product_id).mapped('reserved_availability')) - if number == 0: - number = sum(self.move_ids_without_package.filtered( - lambda ml: ml.product_id == product_id).mapped('product_uom_qty')) - fail_check_text = (f'{fail_check_text}、{product_id.display_name} {number}件' - if fail_check_text != '' else f'{product_id.display_name} {number}件') - return { - 'type': 'ir.actions.act_window', - 'res_model': 'picking.validate.check.wizard', - 'name': '质检不合格提示', - 'view_mode': 'form', - 'target': 'new', - 'context': { - 'default_picking_id': self.id, - 'default_fail_check_text': f'警告:存在不合格产品{fail_check_text},继续调拨请点“确认”,否则请取消?', - 'again_validate': True} - } - res = super(StockPicking, self).button_validate() + try: + context = self.env.context + picking_to_quality = self._get_picking_to_quality() + if not picking_to_quality: return False + need_quality_val = self.get_need_quality_line(picking_to_quality) + if (not context.get('pinking_checkout_quality') and + any(line.get('fail_check_ids') for line in need_quality_val)): + # 回滚事务,为二次确认/取消做准备 + self.env.cr.rollback() + # 获取存在失败的 质检单 调拨单明细行 + check_list = [item for item in need_quality_val if item.get('fail_check_ids')] + fail_check_text = '' + for item in check_list: + move_id, pre_done_qty = item.get('move_id'), item.get('pre_done_qty') + fail_check_text = (f'{fail_check_text}、{move_id.product_id.display_name} {pre_done_qty}件' + if fail_check_text != '' else f'{move_id.product_id.display_name} {pre_done_qty}件') + return { + 'type': 'ir.actions.act_window', + 'res_model': 'picking.validate.check.wizard', + 'name': '质检不合格提示', + 'view_mode': 'form', + 'target': 'new', + 'context': { + 'default_picking_id': self.id, + 'default_fail_check_text': f'警告:存在不合格产品{fail_check_text},继续调拨请点“确认”,否则请取消?', + 'pinking_checkout_quality': True} + } + else: + return False + except Exception as e: + logging.info('pinking_checkout_quality()方法报错:%s' % e) + raise ValidationError('调拨单验证质检单是否合格时报错,请联系管理员处理!!') + + def get_need_quality_line(self, picking_to_quality): + """ + # 对需要进行质检,还没有质检完成的明细行进行统计 + # 1、当【质量标准_控制方式】=“产品、作业”,仅校验“预完成数量”>0的产品行对应的质检单必须处理。 + 2、当【质量标准_控制方式】=“数量”时,仅校验“预完成数量”>0的产品行对应的质检单必须处理: + 1)每一类的“总单数”=【调拨单_需求】时,则已处理的质检单“单数”≥“预完成数量”时,可执行调拨单验证; + 2)每一类的“总单数”<【调拨单_需求】时,则已处理的质检单“单数”≥0时,可执行调拨单验证; + """ + res = [] + for item in picking_to_quality: + need_done_check_ids = self.env['quality.check'] + fail_check_ids = self.env['quality.check'] + move_id, pre_done_qty, check_ids = item.values() + check_ids_1 = check_ids.filtered(lambda qc: qc.measure_on in ('operation', 'product')) + if check_ids_1: + check_ids_1_done = check_ids_1.filtered(lambda qc: qc.quality_state in ('pass', 'fail')) + check_ids_1_fail = check_ids_1.filtered(lambda qc: qc.quality_state == 'fail') + check_ids_1_none = check_ids_1.filtered(lambda qc: qc.quality_state == 'none') + if check_ids_1 and not check_ids_1_done: + need_done_check_ids += check_ids_1_none + if check_ids_1_fail: + fail_check_ids += check_ids_1_fail + + check_ids_2 = check_ids.filtered(lambda qc: qc.measure_on == 'move_line') + if check_ids_2: + check_ids_2_done = check_ids_2.filtered(lambda qc: qc.quality_state in ('pass', 'fail')) + check_ids_2_fail = check_ids_2.filtered(lambda qc: qc.quality_state == 'fail') + check_ids_2_none = check_ids_2.filtered(lambda qc: qc.quality_state == 'none') + if len(check_ids_2) >= pre_done_qty > len(check_ids_2_done): + need_done_check_ids += check_ids_2_none + elif len(check_ids_2) < pre_done_qty and len(check_ids_2_done) == 0: + need_done_check_ids += check_ids_2_none + if check_ids_2_fail: + fail_check_ids += check_ids_2_fail + + if need_done_check_ids or fail_check_ids: + res.append({'move_id': move_id, + 'pre_done_qty': pre_done_qty, + 'check_ids': check_ids, + 'fail_check_ids': fail_check_ids, + 'need_done_check_ids': need_done_check_ids}) return res + + def get_picking_to_quality(self): + self.ensure_one() + return self._get_picking_to_quality() + + def _get_picking_to_quality(self): + """ + 对需要质检的明细行进行统计(针对“预完成数量”>0的行) + """ + quality_piking_line_list = [] + pre_done_qty_lines = self._get_pinking_pre_done_qty() + for line in pre_done_qty_lines: + move_id, pre_done_qty = line.values() + if pre_done_qty == 0: + continue + product_id = move_id.product_id + check_ids = self.check_ids.filtered(lambda c: c.product_id == product_id) + quality_piking_line_list.append({'move_id': move_id, 'pre_done_qty': pre_done_qty, 'check_ids': check_ids}) + return quality_piking_line_list + + def _get_pinking_pre_done_qty(self): + """ + return: 明细行 及 预完成数量 + 1、若调拨单所有明细行的【完成】=0,且任意行的【预留】<【需求】,则验证时将会话是否需创建欠单。 + ---->此时“预完成数量”=【预留】 + 2、若调拨单任意行的0<【完成】<【需求】,且则验证时将会话是否需创建欠单 + ---->此时“预完成数量”=【完成】 + """ + if all(move_id.quantity_done == 0 for move_id in self.move_ids_without_package): + pre_done_qty = [{'move_id': move_id, 'pre_done_qty': move_id.reserved_availability} for move_id in + self.move_ids_without_package] + else: + pre_done_qty = [{'move_id': move_id, 'pre_done_qty': move_id.quantity_done} for move_id in + self.move_ids_without_package] + return pre_done_qty From 98f8430c45f3b464c8398f76beb07970d8c38924 Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Tue, 24 Jun 2025 14:32:40 +0800 Subject: [PATCH 02/11] =?UTF-8?q?Revert=20"=E9=9C=80=E6=B1=82=20=20=20?= =?UTF-8?q?=E8=B0=83=E6=8B=A8=E5=8D=95=E5=85=B3=E8=81=94=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E6=98=AF=E5=90=A6=E5=AE=8C=E6=88=90=E8=B4=A8=E9=87=8F=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E6=97=B6=EF=BC=8C=E5=8F=AF=E5=85=88=E6=8E=92=E9=99=A4?= =?UTF-8?q?=E6=AC=A0=E5=8D=95=E9=87=8F=E5=90=8E=E5=86=8D=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=20=20=E5=BC=80=E5=8F=91"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 912847ae33135bc76e64312f524905e6a26f36b9. --- sf_quality/models/stock.py | 181 +++++++------------------------------ 1 file changed, 35 insertions(+), 146 deletions(-) diff --git a/sf_quality/models/stock.py b/sf_quality/models/stock.py index 3a68ea30..add80f8a 100644 --- a/sf_quality/models/stock.py +++ b/sf_quality/models/stock.py @@ -1,41 +1,11 @@ -import logging - from odoo import api, models -from odoo.exceptions import ValidationError, UserError class StockPicking(models.Model): _inherit = 'stock.picking' - def _compute_check(self): - super()._compute_check() - for picking in self: - picking_to_quality = picking.get_picking_to_quality() - if not picking_to_quality: - picking.quality_check_todo = False - break - else: - need_quality_line = picking.get_need_quality_line(picking_to_quality) - if not need_quality_line or all(not line.get('need_done_check_ids') for line in need_quality_line): - picking.quality_check_todo = False - - def check_quality(self): - self.ensure_one() - # checkable_products = self.mapped('move_line_ids').mapped('product_id') - # checks = self.check_ids.filtered(lambda check: check.quality_state == 'none' and ( - # check.product_id in checkable_products or check.measure_on == 'operation')) - checks = self.env['quality.check'] - picking_to_quality = self._get_picking_to_quality() - need_quality_line = self.get_need_quality_line(picking_to_quality) - if need_quality_line and any(line.get('need_done_check_ids') for line in need_quality_line): - for item in need_quality_line: - checks += item.get('need_done_check_ids') - if checks: - return checks.action_open_quality_check_wizard() - return False - def button_validate(self): - """= + """ 出厂检验报告上传 """ @@ -47,124 +17,43 @@ class StockPicking(models.Model): if not out_quality_check.is_factory_report_uploaded: if out_quality_check and self.state == 'assigned': out_quality_check.upload_factory_report() - quality_action = self.pinking_checkout_quality() - if quality_action: - return quality_action - res = super(StockPicking, self).button_validate() - return res - def pinking_checkout_quality(self): """ 调拨单若关联了质量检查单,验证调拨单时,应校验是否有不合格品,若存在,应弹窗提示: “警告:存在不合格产品XXXX n 件、YYYYY m件,继续调拨请点“确认”,否则请取消?” """ - try: - context = self.env.context - picking_to_quality = self._get_picking_to_quality() - if not picking_to_quality: return False - need_quality_val = self.get_need_quality_line(picking_to_quality) - if (not context.get('pinking_checkout_quality') and - any(line.get('fail_check_ids') for line in need_quality_val)): - # 回滚事务,为二次确认/取消做准备 - self.env.cr.rollback() - # 获取存在失败的 质检单 调拨单明细行 - check_list = [item for item in need_quality_val if item.get('fail_check_ids')] - fail_check_text = '' - for item in check_list: - move_id, pre_done_qty = item.get('move_id'), item.get('pre_done_qty') - fail_check_text = (f'{fail_check_text}、{move_id.product_id.display_name} {pre_done_qty}件' - if fail_check_text != '' else f'{move_id.product_id.display_name} {pre_done_qty}件') - return { - 'type': 'ir.actions.act_window', - 'res_model': 'picking.validate.check.wizard', - 'name': '质检不合格提示', - 'view_mode': 'form', - 'target': 'new', - 'context': { - 'default_picking_id': self.id, - 'default_fail_check_text': f'警告:存在不合格产品{fail_check_text},继续调拨请点“确认”,否则请取消?', - 'pinking_checkout_quality': True} - } - else: - return False - except Exception as e: - logging.info('pinking_checkout_quality()方法报错:%s' % e) - raise ValidationError('调拨单验证质检单是否合格时报错,请联系管理员处理!!') - - def get_need_quality_line(self, picking_to_quality): - """ - # 对需要进行质检,还没有质检完成的明细行进行统计 - # 1、当【质量标准_控制方式】=“产品、作业”,仅校验“预完成数量”>0的产品行对应的质检单必须处理。 - 2、当【质量标准_控制方式】=“数量”时,仅校验“预完成数量”>0的产品行对应的质检单必须处理: - 1)每一类的“总单数”=【调拨单_需求】时,则已处理的质检单“单数”≥“预完成数量”时,可执行调拨单验证; - 2)每一类的“总单数”<【调拨单_需求】时,则已处理的质检单“单数”≥0时,可执行调拨单验证; - """ - res = [] - for item in picking_to_quality: - need_done_check_ids = self.env['quality.check'] - fail_check_ids = self.env['quality.check'] - move_id, pre_done_qty, check_ids = item.values() - check_ids_1 = check_ids.filtered(lambda qc: qc.measure_on in ('operation', 'product')) - if check_ids_1: - check_ids_1_done = check_ids_1.filtered(lambda qc: qc.quality_state in ('pass', 'fail')) - check_ids_1_fail = check_ids_1.filtered(lambda qc: qc.quality_state == 'fail') - check_ids_1_none = check_ids_1.filtered(lambda qc: qc.quality_state == 'none') - if check_ids_1 and not check_ids_1_done: - need_done_check_ids += check_ids_1_none - if check_ids_1_fail: - fail_check_ids += check_ids_1_fail - - check_ids_2 = check_ids.filtered(lambda qc: qc.measure_on == 'move_line') - if check_ids_2: - check_ids_2_done = check_ids_2.filtered(lambda qc: qc.quality_state in ('pass', 'fail')) - check_ids_2_fail = check_ids_2.filtered(lambda qc: qc.quality_state == 'fail') - check_ids_2_none = check_ids_2.filtered(lambda qc: qc.quality_state == 'none') - if len(check_ids_2) >= pre_done_qty > len(check_ids_2_done): - need_done_check_ids += check_ids_2_none - elif len(check_ids_2) < pre_done_qty and len(check_ids_2_done) == 0: - need_done_check_ids += check_ids_2_none - if check_ids_2_fail: - fail_check_ids += check_ids_2_fail - - if need_done_check_ids or fail_check_ids: - res.append({'move_id': move_id, - 'pre_done_qty': pre_done_qty, - 'check_ids': check_ids, - 'fail_check_ids': fail_check_ids, - 'need_done_check_ids': need_done_check_ids}) + context = self.env.context + if not context.get('again_validate') and self.quality_check_ids.filtered(lambda qc: qc.quality_state == 'fail'): + # 回滚事务,为二次确认/取消做准备 + self.env.cr.rollback() + quality_check_ids = self.quality_check_ids.filtered(lambda qc: qc.quality_state == 'fail') + product_list = list(set([quality_check_id.product_id for quality_check_id in quality_check_ids])) + fail_check_text = '' + for product_id in product_list: + check_ids = quality_check_ids.filtered(lambda qc: qc.product_id == product_id) + if all(check_id.measure_on == 'move_line' for check_id in check_ids): + number = sum(check_ids.mapped('qty_line')) + else: + number = sum(self.move_ids_without_package.filtered( + lambda ml: ml.product_id == product_id).mapped('quantity_done')) + if number == 0: + number = sum(self.move_ids_without_package.filtered( + lambda ml: ml.product_id == product_id).mapped('reserved_availability')) + if number == 0: + number = sum(self.move_ids_without_package.filtered( + lambda ml: ml.product_id == product_id).mapped('product_uom_qty')) + fail_check_text = (f'{fail_check_text}、{product_id.display_name} {number}件' + if fail_check_text != '' else f'{product_id.display_name} {number}件') + return { + 'type': 'ir.actions.act_window', + 'res_model': 'picking.validate.check.wizard', + 'name': '质检不合格提示', + 'view_mode': 'form', + 'target': 'new', + 'context': { + 'default_picking_id': self.id, + 'default_fail_check_text': f'警告:存在不合格产品{fail_check_text},继续调拨请点“确认”,否则请取消?', + 'again_validate': True} + } + res = super(StockPicking, self).button_validate() return res - - def get_picking_to_quality(self): - self.ensure_one() - return self._get_picking_to_quality() - - def _get_picking_to_quality(self): - """ - 对需要质检的明细行进行统计(针对“预完成数量”>0的行) - """ - quality_piking_line_list = [] - pre_done_qty_lines = self._get_pinking_pre_done_qty() - for line in pre_done_qty_lines: - move_id, pre_done_qty = line.values() - if pre_done_qty == 0: - continue - product_id = move_id.product_id - check_ids = self.check_ids.filtered(lambda c: c.product_id == product_id) - quality_piking_line_list.append({'move_id': move_id, 'pre_done_qty': pre_done_qty, 'check_ids': check_ids}) - return quality_piking_line_list - - def _get_pinking_pre_done_qty(self): - """ - return: 明细行 及 预完成数量 - 1、若调拨单所有明细行的【完成】=0,且任意行的【预留】<【需求】,则验证时将会话是否需创建欠单。 - ---->此时“预完成数量”=【预留】 - 2、若调拨单任意行的0<【完成】<【需求】,且则验证时将会话是否需创建欠单 - ---->此时“预完成数量”=【完成】 - """ - if all(move_id.quantity_done == 0 for move_id in self.move_ids_without_package): - pre_done_qty = [{'move_id': move_id, 'pre_done_qty': move_id.reserved_availability} for move_id in - self.move_ids_without_package] - else: - pre_done_qty = [{'move_id': move_id, 'pre_done_qty': move_id.quantity_done} for move_id in - self.move_ids_without_package] - return pre_done_qty From 579b7138e763512055eff01b897dea5ee761804f Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Tue, 24 Jun 2025 14:41:49 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E9=9C=80=E6=B1=82=20=20=E8=B0=83?= =?UTF-8?q?=E6=8B=A8=E5=8D=95=E5=85=B3=E8=81=94=E6=A0=A1=E9=AA=8C=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=AE=8C=E6=88=90=E8=B4=A8=E9=87=8F=E6=A3=80=E6=9F=A5?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E5=8F=AF=E5=85=88=E6=8E=92=E9=99=A4=E6=AC=A0?= =?UTF-8?q?=E5=8D=95=E9=87=8F=E5=90=8E=E5=86=8D=E6=A0=A1=E9=AA=8C=20?= =?UTF-8?q?=E5=BC=80=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_quality/models/stock.py | 181 ++++++++++++++++++++++++++++++------- 1 file changed, 146 insertions(+), 35 deletions(-) diff --git a/sf_quality/models/stock.py b/sf_quality/models/stock.py index add80f8a..3a68ea30 100644 --- a/sf_quality/models/stock.py +++ b/sf_quality/models/stock.py @@ -1,11 +1,41 @@ +import logging + from odoo import api, models +from odoo.exceptions import ValidationError, UserError class StockPicking(models.Model): _inherit = 'stock.picking' + def _compute_check(self): + super()._compute_check() + for picking in self: + picking_to_quality = picking.get_picking_to_quality() + if not picking_to_quality: + picking.quality_check_todo = False + break + else: + need_quality_line = picking.get_need_quality_line(picking_to_quality) + if not need_quality_line or all(not line.get('need_done_check_ids') for line in need_quality_line): + picking.quality_check_todo = False + + def check_quality(self): + self.ensure_one() + # checkable_products = self.mapped('move_line_ids').mapped('product_id') + # checks = self.check_ids.filtered(lambda check: check.quality_state == 'none' and ( + # check.product_id in checkable_products or check.measure_on == 'operation')) + checks = self.env['quality.check'] + picking_to_quality = self._get_picking_to_quality() + need_quality_line = self.get_need_quality_line(picking_to_quality) + if need_quality_line and any(line.get('need_done_check_ids') for line in need_quality_line): + for item in need_quality_line: + checks += item.get('need_done_check_ids') + if checks: + return checks.action_open_quality_check_wizard() + return False + def button_validate(self): - """ + """= 出厂检验报告上传 """ @@ -17,43 +47,124 @@ class StockPicking(models.Model): if not out_quality_check.is_factory_report_uploaded: if out_quality_check and self.state == 'assigned': out_quality_check.upload_factory_report() + quality_action = self.pinking_checkout_quality() + if quality_action: + return quality_action + res = super(StockPicking, self).button_validate() + return res + def pinking_checkout_quality(self): """ 调拨单若关联了质量检查单,验证调拨单时,应校验是否有不合格品,若存在,应弹窗提示: “警告:存在不合格产品XXXX n 件、YYYYY m件,继续调拨请点“确认”,否则请取消?” """ - context = self.env.context - if not context.get('again_validate') and self.quality_check_ids.filtered(lambda qc: qc.quality_state == 'fail'): - # 回滚事务,为二次确认/取消做准备 - self.env.cr.rollback() - quality_check_ids = self.quality_check_ids.filtered(lambda qc: qc.quality_state == 'fail') - product_list = list(set([quality_check_id.product_id for quality_check_id in quality_check_ids])) - fail_check_text = '' - for product_id in product_list: - check_ids = quality_check_ids.filtered(lambda qc: qc.product_id == product_id) - if all(check_id.measure_on == 'move_line' for check_id in check_ids): - number = sum(check_ids.mapped('qty_line')) - else: - number = sum(self.move_ids_without_package.filtered( - lambda ml: ml.product_id == product_id).mapped('quantity_done')) - if number == 0: - number = sum(self.move_ids_without_package.filtered( - lambda ml: ml.product_id == product_id).mapped('reserved_availability')) - if number == 0: - number = sum(self.move_ids_without_package.filtered( - lambda ml: ml.product_id == product_id).mapped('product_uom_qty')) - fail_check_text = (f'{fail_check_text}、{product_id.display_name} {number}件' - if fail_check_text != '' else f'{product_id.display_name} {number}件') - return { - 'type': 'ir.actions.act_window', - 'res_model': 'picking.validate.check.wizard', - 'name': '质检不合格提示', - 'view_mode': 'form', - 'target': 'new', - 'context': { - 'default_picking_id': self.id, - 'default_fail_check_text': f'警告:存在不合格产品{fail_check_text},继续调拨请点“确认”,否则请取消?', - 'again_validate': True} - } - res = super(StockPicking, self).button_validate() + try: + context = self.env.context + picking_to_quality = self._get_picking_to_quality() + if not picking_to_quality: return False + need_quality_val = self.get_need_quality_line(picking_to_quality) + if (not context.get('pinking_checkout_quality') and + any(line.get('fail_check_ids') for line in need_quality_val)): + # 回滚事务,为二次确认/取消做准备 + self.env.cr.rollback() + # 获取存在失败的 质检单 调拨单明细行 + check_list = [item for item in need_quality_val if item.get('fail_check_ids')] + fail_check_text = '' + for item in check_list: + move_id, pre_done_qty = item.get('move_id'), item.get('pre_done_qty') + fail_check_text = (f'{fail_check_text}、{move_id.product_id.display_name} {pre_done_qty}件' + if fail_check_text != '' else f'{move_id.product_id.display_name} {pre_done_qty}件') + return { + 'type': 'ir.actions.act_window', + 'res_model': 'picking.validate.check.wizard', + 'name': '质检不合格提示', + 'view_mode': 'form', + 'target': 'new', + 'context': { + 'default_picking_id': self.id, + 'default_fail_check_text': f'警告:存在不合格产品{fail_check_text},继续调拨请点“确认”,否则请取消?', + 'pinking_checkout_quality': True} + } + else: + return False + except Exception as e: + logging.info('pinking_checkout_quality()方法报错:%s' % e) + raise ValidationError('调拨单验证质检单是否合格时报错,请联系管理员处理!!') + + def get_need_quality_line(self, picking_to_quality): + """ + # 对需要进行质检,还没有质检完成的明细行进行统计 + # 1、当【质量标准_控制方式】=“产品、作业”,仅校验“预完成数量”>0的产品行对应的质检单必须处理。 + 2、当【质量标准_控制方式】=“数量”时,仅校验“预完成数量”>0的产品行对应的质检单必须处理: + 1)每一类的“总单数”=【调拨单_需求】时,则已处理的质检单“单数”≥“预完成数量”时,可执行调拨单验证; + 2)每一类的“总单数”<【调拨单_需求】时,则已处理的质检单“单数”≥0时,可执行调拨单验证; + """ + res = [] + for item in picking_to_quality: + need_done_check_ids = self.env['quality.check'] + fail_check_ids = self.env['quality.check'] + move_id, pre_done_qty, check_ids = item.values() + check_ids_1 = check_ids.filtered(lambda qc: qc.measure_on in ('operation', 'product')) + if check_ids_1: + check_ids_1_done = check_ids_1.filtered(lambda qc: qc.quality_state in ('pass', 'fail')) + check_ids_1_fail = check_ids_1.filtered(lambda qc: qc.quality_state == 'fail') + check_ids_1_none = check_ids_1.filtered(lambda qc: qc.quality_state == 'none') + if check_ids_1 and not check_ids_1_done: + need_done_check_ids += check_ids_1_none + if check_ids_1_fail: + fail_check_ids += check_ids_1_fail + + check_ids_2 = check_ids.filtered(lambda qc: qc.measure_on == 'move_line') + if check_ids_2: + check_ids_2_done = check_ids_2.filtered(lambda qc: qc.quality_state in ('pass', 'fail')) + check_ids_2_fail = check_ids_2.filtered(lambda qc: qc.quality_state == 'fail') + check_ids_2_none = check_ids_2.filtered(lambda qc: qc.quality_state == 'none') + if len(check_ids_2) >= pre_done_qty > len(check_ids_2_done): + need_done_check_ids += check_ids_2_none + elif len(check_ids_2) < pre_done_qty and len(check_ids_2_done) == 0: + need_done_check_ids += check_ids_2_none + if check_ids_2_fail: + fail_check_ids += check_ids_2_fail + + if need_done_check_ids or fail_check_ids: + res.append({'move_id': move_id, + 'pre_done_qty': pre_done_qty, + 'check_ids': check_ids, + 'fail_check_ids': fail_check_ids, + 'need_done_check_ids': need_done_check_ids}) return res + + def get_picking_to_quality(self): + self.ensure_one() + return self._get_picking_to_quality() + + def _get_picking_to_quality(self): + """ + 对需要质检的明细行进行统计(针对“预完成数量”>0的行) + """ + quality_piking_line_list = [] + pre_done_qty_lines = self._get_pinking_pre_done_qty() + for line in pre_done_qty_lines: + move_id, pre_done_qty = line.values() + if pre_done_qty == 0: + continue + product_id = move_id.product_id + check_ids = self.check_ids.filtered(lambda c: c.product_id == product_id) + quality_piking_line_list.append({'move_id': move_id, 'pre_done_qty': pre_done_qty, 'check_ids': check_ids}) + return quality_piking_line_list + + def _get_pinking_pre_done_qty(self): + """ + return: 明细行 及 预完成数量 + 1、若调拨单所有明细行的【完成】=0,且任意行的【预留】<【需求】,则验证时将会话是否需创建欠单。 + ---->此时“预完成数量”=【预留】 + 2、若调拨单任意行的0<【完成】<【需求】,且则验证时将会话是否需创建欠单 + ---->此时“预完成数量”=【完成】 + """ + if all(move_id.quantity_done == 0 for move_id in self.move_ids_without_package): + pre_done_qty = [{'move_id': move_id, 'pre_done_qty': move_id.reserved_availability} for move_id in + self.move_ids_without_package] + else: + pre_done_qty = [{'move_id': move_id, 'pre_done_qty': move_id.quantity_done} for move_id in + self.move_ids_without_package] + return pre_done_qty From 00922e3674466ba76f1e6e4ecb2df7730a0d9ed2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Tue, 24 Jun 2025 15:35:19 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=B7=A5=E5=8D=95?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E5=AF=B9=E5=BA=94=E5=90=8D=E5=AD=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_machine_connect/controllers/controllers.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/sf_machine_connect/controllers/controllers.py b/sf_machine_connect/controllers/controllers.py index de4a8a33..8316411e 100644 --- a/sf_machine_connect/controllers/controllers.py +++ b/sf_machine_connect/controllers/controllers.py @@ -866,6 +866,8 @@ class Sf_Dashboard_Connect(http.Controller): request.update_context(lang='zh_CN') plan_obj = request.env['sf.production.plan'].sudo() work_order_obj = request.env['mrp.workorder'].sudo() + # 获取mrp.workorder的state字段的selection内容 + state_dict = dict(request.env['mrp.workorder'].sudo()._fields['state'].selection) line_list = ast.literal_eval(kw['line_list']) begin_time_str = kw['begin_time'].strip('"') end_time_str = kw['end_time'].strip('"') @@ -964,14 +966,6 @@ class Sf_Dashboard_Connect(http.Controller): material_match = re.search(material_pattern, blank_name) material = material_match.group(1) if material_match else 'No match found' - state_dict = { - 'draft': '待排程', - 'done': '已排程', - 'processing': '生产中', - 'finished': '已完成', - 'ready': '待加工', - 'progress': '生产中', - } line_dict = { 'sequence': not_done_index, From 0a79a4e3367fff50dba6f6b03e4d835776ddfa5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Tue, 24 Jun 2025 15:50:45 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=9C=AA=E5=AE=8C?= =?UTF-8?q?=E6=88=90=E8=AE=A2=E5=8D=95=E6=98=8E=E7=BB=86=E7=9A=84=E5=88=A4?= =?UTF-8?q?=E6=96=AD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_machine_connect/controllers/controllers.py | 38 ++++++++++--------- 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/sf_machine_connect/controllers/controllers.py b/sf_machine_connect/controllers/controllers.py index 8316411e..69ea3c14 100644 --- a/sf_machine_connect/controllers/controllers.py +++ b/sf_machine_connect/controllers/controllers.py @@ -880,13 +880,13 @@ class Sf_Dashboard_Connect(http.Controller): current_time = datetime.now() time_48_hours_ago = current_time - timedelta(hours=48) - # 计划量,目前只能从mail.message中筛选出 - plan_order_messages = request.env['mail.message'].sudo().search([ - ('model', '=', 'mrp.workorder'), - ('create_date', '>=', time_48_hours_ago.strftime('%Y-%m-%d %H:%M:%S')), - ('tracking_value_ids.field_desc', '=', '状态'), - ('tracking_value_ids.new_value_char', 'in', ['就绪', '生产中']) - ]) + # # 计划量,目前只能从mail.message中筛选出 + # plan_order_messages = request.env['mail.message'].sudo().search([ + # ('model', '=', 'mrp.workorder'), + # ('create_date', '>=', time_48_hours_ago.strftime('%Y-%m-%d %H:%M:%S')), + # ('tracking_value_ids.field_desc', '=', '状态'), + # ('tracking_value_ids.new_value_char', 'in', ['就绪', '生产中']) + # ]) for line in line_list: not_done_data = [] @@ -908,16 +908,18 @@ class Sf_Dashboard_Connect(http.Controller): # [('production_line_id.name', '=', line), ('state', 'not in', ['finished']), # ('production_id.state', 'not in', ['cancel', 'done']), ('active', '=', True) # ]) - # not_done_orders = work_order_obj.search(work_order_domain + - # [('state', 'in', ['ready', 'progress'])], order='id asc' - # ) - not_done_orders = request.env['mrp.workorder'].sudo().browse(plan_order_messages.mapped('res_id')) - if line == '业绩总览': - not_done_orders = not_done_orders.filtered(lambda o: o.routing_type in ['人工线下加工', 'CNC加工']) - elif line == '人工线下加工中心': - not_done_orders = not_done_orders.filtered(lambda o: o.routing_type == '人工线下加工') - else: - not_done_orders = not_done_orders.filtered(lambda o: o.routing_type == 'CNC加工' and o.production_line_id.name == line) + not_done_orders = work_order_obj.search(work_order_domain + [ + ('state', 'in', ['ready', 'progress']), + ('date_planned_start', '>=', time_48_hours_ago) + ], order='id asc' + ) + # not_done_orders = request.env['mrp.workorder'].sudo().browse(plan_order_messages.mapped('res_id')) + # if line == '业绩总览': + # not_done_orders = not_done_orders.filtered(lambda o: o.routing_type in ['人工线下加工', 'CNC加工']) + # elif line == '人工线下加工中心': + # not_done_orders = not_done_orders.filtered(lambda o: o.routing_type == '人工线下加工') + # else: + # not_done_orders = not_done_orders.filtered(lambda o: o.routing_type == 'CNC加工' and o.production_line_id.name == line) # 完成订单 @@ -996,7 +998,7 @@ class Sf_Dashboard_Connect(http.Controller): line_dict = { 'sequence': done_index, - 'workorder_name': finish_order.name, + 'workorder_name': finish_order.production_id.name, 'blank_name': blank_name, 'material': material, 'dimensions': dimensions, From 9922402b3b0b68f79ae5b9ee41a1e3410cf94074 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Tue, 24 Jun 2025 15:56:33 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=98=8E=E7=BB=86?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_machine_connect/controllers/controllers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sf_machine_connect/controllers/controllers.py b/sf_machine_connect/controllers/controllers.py index 69ea3c14..397840f9 100644 --- a/sf_machine_connect/controllers/controllers.py +++ b/sf_machine_connect/controllers/controllers.py @@ -1002,7 +1002,7 @@ class Sf_Dashboard_Connect(http.Controller): 'blank_name': blank_name, 'material': material, 'dimensions': dimensions, - 'order_qty': order.qty_produced, + 'order_qty': finish_order.qty_produced, 'finish_time': finish_order.date_finished.strftime( '%Y-%m-%d %H:%M:%S') if finish_order.date_finished else ' ' From f5ed94866b26d8897deec41bb984e74344bbba21 Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Tue, 24 Jun 2025 16:59:38 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E8=B0=83=E6=8B=A8=E5=8D=95=E9=9C=80?= =?UTF-8?q?=E9=AA=8C=E8=AF=81=E8=B4=A8=E6=A3=80=E5=8D=95=E6=95=B0=E9=87=8F?= =?UTF-8?q?=E6=96=B9=E6=B3=95=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_quality/models/stock.py | 75 +++++++++++++++++++++----------------- 1 file changed, 42 insertions(+), 33 deletions(-) diff --git a/sf_quality/models/stock.py b/sf_quality/models/stock.py index 3a68ea30..3de28c7c 100644 --- a/sf_quality/models/stock.py +++ b/sf_quality/models/stock.py @@ -59,32 +59,33 @@ class StockPicking(models.Model): “警告:存在不合格产品XXXX n 件、YYYYY m件,继续调拨请点“确认”,否则请取消?” """ try: + self.ensure_one() context = self.env.context - picking_to_quality = self._get_picking_to_quality() - if not picking_to_quality: return False - need_quality_val = self.get_need_quality_line(picking_to_quality) - if (not context.get('pinking_checkout_quality') and - any(line.get('fail_check_ids') for line in need_quality_val)): - # 回滚事务,为二次确认/取消做准备 - self.env.cr.rollback() - # 获取存在失败的 质检单 调拨单明细行 - check_list = [item for item in need_quality_val if item.get('fail_check_ids')] - fail_check_text = '' - for item in check_list: - move_id, pre_done_qty = item.get('move_id'), item.get('pre_done_qty') - fail_check_text = (f'{fail_check_text}、{move_id.product_id.display_name} {pre_done_qty}件' - if fail_check_text != '' else f'{move_id.product_id.display_name} {pre_done_qty}件') - return { - 'type': 'ir.actions.act_window', - 'res_model': 'picking.validate.check.wizard', - 'name': '质检不合格提示', - 'view_mode': 'form', - 'target': 'new', - 'context': { - 'default_picking_id': self.id, - 'default_fail_check_text': f'警告:存在不合格产品{fail_check_text},继续调拨请点“确认”,否则请取消?', - 'pinking_checkout_quality': True} - } + if not context.get('pinking_checkout_quality'): + picking_to_quality = self._get_picking_to_quality() + if not picking_to_quality: return False + need_quality_val = self.get_need_quality_line(picking_to_quality) + if any(line.get('fail_check_ids') for line in need_quality_val): + # 回滚事务,为二次确认/取消做准备 + self.env.cr.rollback() + # 获取存在失败的 质检单 调拨单明细行 + check_list = [item for item in need_quality_val if item.get('fail_check_ids')] + fail_check_text = '' + for item in check_list: + move_id, pre_done_qty = item.get('move_id'), item.get('pre_done_qty') + fail_check_text = (f'{fail_check_text}、{move_id.product_id.display_name} {pre_done_qty}件' + if fail_check_text != '' else f'{move_id.product_id.display_name} {pre_done_qty}件') + return { + 'type': 'ir.actions.act_window', + 'res_model': 'picking.validate.check.wizard', + 'name': '质检不合格提示', + 'view_mode': 'form', + 'target': 'new', + 'context': { + 'default_picking_id': self.id, + 'default_fail_check_text': f'警告:存在不合格产品{fail_check_text},继续调拨请点“确认”,否则请取消?', + 'pinking_checkout_quality': True} + } else: return False except Exception as e: @@ -119,9 +120,11 @@ class StockPicking(models.Model): check_ids_2_done = check_ids_2.filtered(lambda qc: qc.quality_state in ('pass', 'fail')) check_ids_2_fail = check_ids_2.filtered(lambda qc: qc.quality_state == 'fail') check_ids_2_none = check_ids_2.filtered(lambda qc: qc.quality_state == 'none') - if len(check_ids_2) >= pre_done_qty > len(check_ids_2_done): + # 每一类的“总单数”=【调拨单_需求】时,则已处理的质检单“单数”≥“预完成数量”时,可执行调拨单验证; + if len(check_ids_2) >= move_id.product_uom_qty and len(check_ids_2_done) < pre_done_qty: need_done_check_ids += check_ids_2_none - elif len(check_ids_2) < pre_done_qty and len(check_ids_2_done) == 0: + # 每一类的“总单数”<【调拨单_需求】时,则已处理的质检单“单数”≥0时,可执行调拨单验证 + elif len(check_ids_2) < move_id.product_uom_qty and len(check_ids_2_done) == 0: need_done_check_ids += check_ids_2_none if check_ids_2_fail: fail_check_ids += check_ids_2_fail @@ -161,10 +164,16 @@ class StockPicking(models.Model): 2、若调拨单任意行的0<【完成】<【需求】,且则验证时将会话是否需创建欠单 ---->此时“预完成数量”=【完成】 """ - if all(move_id.quantity_done == 0 for move_id in self.move_ids_without_package): - pre_done_qty = [{'move_id': move_id, 'pre_done_qty': move_id.reserved_availability} for move_id in - self.move_ids_without_package] - else: - pre_done_qty = [{'move_id': move_id, 'pre_done_qty': move_id.quantity_done} for move_id in - self.move_ids_without_package] + # if all(move_id.quantity_done == 0 for move_id in self.move_ids_without_package): + # pre_done_qty = [{'move_id': move_id, 'pre_done_qty': move_id.reserved_availability} for move_id in + # self.move_ids_without_package] + # else: + # pre_done_qty = [{'move_id': move_id, 'pre_done_qty': move_id.quantity_done} for move_id in + # self.move_ids_without_package] + pre_done_qty = [] + for move_id in self.move_ids_without_package: + if move_id.quantity_done > 0: + pre_done_qty.append({'move_id': move_id, 'pre_done_qty': move_id.quantity_done}) + else: + pre_done_qty.append({'move_id': move_id, 'pre_done_qty': move_id.reserved_availability}) return pre_done_qty From 133eac4a5c86066549e2773bd2fae2b0ac1a94dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Wed, 25 Jun 2025 08:43:59 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E6=97=A5=E8=AE=A1=E5=88=92=E9=87=8F?= =?UTF-8?q?=E5=AF=B9=E5=B7=A5=E5=8D=95id=E5=8E=BB=E9=87=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_machine_connect/controllers/controllers.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sf_machine_connect/controllers/controllers.py b/sf_machine_connect/controllers/controllers.py index 397840f9..25fda400 100644 --- a/sf_machine_connect/controllers/controllers.py +++ b/sf_machine_connect/controllers/controllers.py @@ -707,9 +707,11 @@ class Sf_Dashboard_Connect(http.Controller): interval_plan_orders = plan_order_messages.filtered( lambda o: o.create_date >= start_time and o.create_date <= end_time - ) + ) - interval_orders = request.env['mrp.workorder'].sudo().browse(interval_plan_orders.mapped('res_id')) + interval_order_ids = set(interval_plan_orders.mapped('res_id')) + + interval_orders = request.env['mrp.workorder'].sudo().browse(interval_order_ids) if line == '业绩总览': interval_orders = interval_orders.filtered(lambda o: o.routing_type in ['人工线下加工', 'CNC加工']) elif line == '人工线下加工中心': From f165bec6629f04d13717eff6ae887546676dcb37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=83=A1=E5=B0=A7?= Date: Wed, 25 Jun 2025 09:42:53 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E5=BE=85=E5=AE=8C=E5=B7=A5=E5=B7=A5?= =?UTF-8?q?=E5=8D=95=E6=98=8E=E7=BB=86=EF=BC=8C=E6=8E=A7=E5=88=B6=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E4=B8=BA=E5=A4=A7=E4=BA=8E48=E5=B0=8F=E6=97=B6?= =?UTF-8?q?=EF=BC=8C=E5=B0=8F=E4=BA=8E=E5=BD=93=E5=89=8D=E6=97=B6=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_machine_connect/controllers/controllers.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/sf_machine_connect/controllers/controllers.py b/sf_machine_connect/controllers/controllers.py index 25fda400..96461902 100644 --- a/sf_machine_connect/controllers/controllers.py +++ b/sf_machine_connect/controllers/controllers.py @@ -912,17 +912,10 @@ class Sf_Dashboard_Connect(http.Controller): # ]) not_done_orders = work_order_obj.search(work_order_domain + [ ('state', 'in', ['ready', 'progress']), - ('date_planned_start', '>=', time_48_hours_ago) + ('date_planned_start', '>=', time_48_hours_ago), + ('date_planned_start', '<=', current_time) ], order='id asc' ) - # not_done_orders = request.env['mrp.workorder'].sudo().browse(plan_order_messages.mapped('res_id')) - # if line == '业绩总览': - # not_done_orders = not_done_orders.filtered(lambda o: o.routing_type in ['人工线下加工', 'CNC加工']) - # elif line == '人工线下加工中心': - # not_done_orders = not_done_orders.filtered(lambda o: o.routing_type == '人工线下加工') - # else: - # not_done_orders = not_done_orders.filtered(lambda o: o.routing_type == 'CNC加工' and o.production_line_id.name == line) - # 完成订单 # 获取当前时间,并计算24小时前的时间 From 28ade4ac72a33a61da65148a3a04018e20f17137 Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Wed, 25 Jun 2025 13:57:56 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E5=AE=8C=E6=88=90=20=20=E7=89=A9?= =?UTF-8?q?=E6=96=99=E9=9C=80=E6=B1=82=E8=AE=A1=E5=88=92=E4=B8=BB=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E5=87=86=E5=A4=87=EF=BC=9A=E5=BA=93=E5=AD=98=E8=B7=AF?= =?UTF-8?q?=E7=BA=BF=20=20=E9=9C=80=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sf_demand_plan/__manifest__.py | 2 + sf_demand_plan/data/stock_route_group.xml | 21 ++++++++ sf_demand_plan/models/__init__.py | 1 + .../models/sf_production_demand_plan.py | 16 +++++- sf_demand_plan/models/stock_route.py | 49 +++++++++++++++++++ sf_demand_plan/security/ir.model.access.csv | 3 ++ sf_demand_plan/views/demand_plan.xml | 3 +- sf_demand_plan/views/stock_route.xml | 21 ++++++++ sf_mrs_connect/models/mrp_production.py | 2 + 9 files changed, 116 insertions(+), 2 deletions(-) create mode 100644 sf_demand_plan/data/stock_route_group.xml create mode 100644 sf_demand_plan/models/stock_route.py create mode 100644 sf_demand_plan/views/stock_route.xml diff --git a/sf_demand_plan/__manifest__.py b/sf_demand_plan/__manifest__.py index e65fdca7..59457102 100644 --- a/sf_demand_plan/__manifest__.py +++ b/sf_demand_plan/__manifest__.py @@ -13,7 +13,9 @@ 'depends': ['sf_plan','jikimo_printing'], 'data': [ 'security/ir.model.access.csv', + 'data/stock_route_group.xml', 'views/demand_plan.xml', + 'views/stock_route.xml', 'wizard/sf_demand_plan_print_wizard_view.xml', ], 'demo': [ diff --git a/sf_demand_plan/data/stock_route_group.xml b/sf_demand_plan/data/stock_route_group.xml new file mode 100644 index 00000000..1b4a0b84 --- /dev/null +++ b/sf_demand_plan/data/stock_route_group.xml @@ -0,0 +1,21 @@ + + + + + 自动化产线加工 + automation + + + 人工线下加工 + manual + + + 外购 + purchase + + + 委外加工 + outsourcing + + + \ No newline at end of file diff --git a/sf_demand_plan/models/__init__.py b/sf_demand_plan/models/__init__.py index a0554c11..70c1bbc8 100644 --- a/sf_demand_plan/models/__init__.py +++ b/sf_demand_plan/models/__init__.py @@ -2,3 +2,4 @@ from . import sf_production_demand_plan from . import sale_order +from . import stock_route diff --git a/sf_demand_plan/models/sf_production_demand_plan.py b/sf_demand_plan/models/sf_production_demand_plan.py index 49cbe926..d43c2eb6 100644 --- a/sf_demand_plan/models/sf_production_demand_plan.py +++ b/sf_demand_plan/models/sf_production_demand_plan.py @@ -88,6 +88,9 @@ class SfProductionDemandPlan(models.Model): string='订单状态', related='sale_order_line_id.state') route_id = fields.Many2one('stock.route', string='路线', related='sale_order_line_id.route_id', store=True) + route_ids = fields.Many2many('stock.route', 'stock_route_demand_plan', 'demand_plan_id', 'route_id', '路线', + domain=[('demand_plan_selectable', '=', True)], compute='_compute_route_ids', + store=True) contract_date = fields.Date('合同日期', related='sale_order_id.contract_date') date_order = fields.Datetime('下单日期', related='sale_order_id.date_order') contract_code = fields.Char('合同号', related='sale_order_id.contract_code', store=True) @@ -135,6 +138,18 @@ class SfProductionDemandPlan(models.Model): outsourcing_purchase_request = fields.Char('委外采购申请单') + @api.depends('supply_method') + def _compute_route_ids(self): + for pdp in self: + if pdp.supply_method: + group_id = self.env['stock.route.group'].sudo().search([('code', '=', pdp.supply_method)]) + route_ids = self.env['stock.route'].sudo().search( + [('demand_plan_selectable', '=', True), ('stock_route_group_ids', '=', group_id.id)]) + if route_ids: + pdp.route_ids = route_ids.ids + break + pdp.route_ids = None + @api.depends('sale_order_id.state', 'sale_order_id.mrp_production_ids.schedule_state', 'sale_order_id.order_line', 'sale_order_id.mrp_production_ids.state') def _compute_status(self): @@ -332,7 +347,6 @@ class SfProductionDemandPlan(models.Model): for pro_plan in pro_plan_list: pro_plan.do_production_schedule() - def button_action_print(self): return { 'res_model': 'sf.demand.plan.print.wizard', diff --git a/sf_demand_plan/models/stock_route.py b/sf_demand_plan/models/stock_route.py new file mode 100644 index 00000000..20e4b3c9 --- /dev/null +++ b/sf_demand_plan/models/stock_route.py @@ -0,0 +1,49 @@ +from odoo import models, fields, api, _ + + +class SfStockRoute(models.Model): + _inherit = 'stock.route' + + demand_plan_selectable = fields.Boolean("需求计划行") + stock_route_group_ids = fields.Many2many('stock.route.group', 'route_to_group', string='路线组') + demand_plan_ids = fields.Many2many('sf.production.demand.plan', 'stock_route_demand_plan', 'route_id', + 'demand_plan_id', '需求计划', copy=False, compute='_compute_demand_plan_ids', + store=True) + + @api.depends('demand_plan_selectable', 'stock_route_group_ids') + def _compute_demand_plan_ids(self): + for sr in self: + if sr.demand_plan_selectable: + stock_route_group = [srg.code for srg in sr.stock_route_group_ids] + demand_plan_ids = self.env['sf.production.demand.plan'].sudo().search( + [('supply_method', 'in', stock_route_group)]) + if demand_plan_ids: + sr.demand_plan_ids = demand_plan_ids.ids + break + sr.demand_plan_ids = None + + # def name_get(self): + # res = super().name_get() + # if self.env.context.get('demand_plan_search_stock_route_id'): + # demand_plan_id = self.env['sf.production.demand.plan'].sudo().browse( + # int(self.env.context.get('demand_plan_search_stock_route_id'))) + # if demand_plan_id and demand_plan_id.supply_method: + # supply_method = self._set_supply_method(demand_plan_id.supply_method) + # res = [(item[0], f'{item[1]}-{supply_method}') for item in res if len(item) == 2] + # return res + # + # def _set_supply_method(self, supply_method): + # return { + # 'automation': "自动化产线加工", + # 'manual': "人工线下加工", + # 'purchase': "外购", + # 'outsourcing': "委外加工" + # }.get(supply_method) + + +class SfStockRouteGroup(models.Model): + _name = 'stock.route.group' + _description = '路线组' + + name = fields.Char('名称') + code = fields.Char('编码') diff --git a/sf_demand_plan/security/ir.model.access.csv b/sf_demand_plan/security/ir.model.access.csv index 56e8e247..a1bef90a 100644 --- a/sf_demand_plan/security/ir.model.access.csv +++ b/sf_demand_plan/security/ir.model.access.csv @@ -4,3 +4,6 @@ access_sf_production_demand_plan_for_dispatch,sf.production.demand.plan for disp access_sf_demand_plan_print_wizard,sf.demand.plan.print.wizard,model_sf_demand_plan_print_wizard,base.group_user,1,0,0,0 access_sf_demand_plan_print_wizard_for_dispatch,sf.demand.plan.print.wizard for dispatch,model_sf_demand_plan_print_wizard,sf_base.group_plan_dispatch,1,1,0,0 + +access_stock_route_group,stock.route.group,model_stock_route_group,base.group_user,1,0,0,0 +access_stock_route_group_dispatch,stock.route.group.dispatch,model_stock_route_group,sf_base.group_plan_dispatch,1,1,0,0 diff --git a/sf_demand_plan/views/demand_plan.xml b/sf_demand_plan/views/demand_plan.xml index 5b9c425a..a316df5a 100644 --- a/sf_demand_plan/views/demand_plan.xml +++ b/sf_demand_plan/views/demand_plan.xml @@ -38,7 +38,8 @@ - + diff --git a/sf_demand_plan/views/stock_route.xml b/sf_demand_plan/views/stock_route.xml new file mode 100644 index 00000000..c4581acc --- /dev/null +++ b/sf_demand_plan/views/stock_route.xml @@ -0,0 +1,21 @@ + + + + stock.route.form + stock.route + + + + + + + + + + + + + + + + diff --git a/sf_mrs_connect/models/mrp_production.py b/sf_mrs_connect/models/mrp_production.py index ac3f6640..fe2682de 100644 --- a/sf_mrs_connect/models/mrp_production.py +++ b/sf_mrs_connect/models/mrp_production.py @@ -13,6 +13,8 @@ class MrpProduction(models.Model): 生成编程单 """ productions = super().create(vals_list) + if not productions: + return self.browse() # 定义变量存储编程单 grouped_product_programming_no = {} # 定义产品拼接成的制造订单名称 From e3494ce8b70cdefae5a4f7031910fff648cbb452 Mon Sep 17 00:00:00 2001 From: yuxianghui <3437689193@qq.com> Date: Wed, 25 Jun 2025 16:09:32 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=E5=AE=8C=E6=88=90=20=E5=A7=94=E5=A4=96?= =?UTF-8?q?=E5=8A=A0=E5=B7=A5=E9=87=87=E8=B4=AD=E8=AE=A2=E5=8D=95=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0BOM=E5=86=85=E7=89=A9=E6=96=99=E7=9A=84=E9=87=87?= =?UTF-8?q?=E8=B4=AD=E7=94=B3=E8=AF=B7=E4=B8=8E=E9=87=87=E8=B4=AD=E8=AE=A2?= =?UTF-8?q?=E5=8D=95=20=E9=9C=80=E6=B1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- jikimo_purchase_request/__manifest__.py | 1 + .../models/purchase_order.py | 63 +++++++++++++++++++ .../views/purchase_order.xml | 28 +++++++++ 3 files changed, 92 insertions(+) create mode 100644 jikimo_purchase_request/views/purchase_order.xml diff --git a/jikimo_purchase_request/__manifest__.py b/jikimo_purchase_request/__manifest__.py index 2ae6ce67..c6e58a41 100644 --- a/jikimo_purchase_request/__manifest__.py +++ b/jikimo_purchase_request/__manifest__.py @@ -10,6 +10,7 @@ 'data': [ 'security/ir.model.access.csv', 'views/sale_order_view.xml', + 'views/purchase_order.xml', 'views/mrp_production.xml', 'views/purchase_request_view.xml', 'wizard/purchase_request_line_make_purchase_order_view.xml', diff --git a/jikimo_purchase_request/models/purchase_order.py b/jikimo_purchase_request/models/purchase_order.py index 95f81e9f..29e6c646 100644 --- a/jikimo_purchase_request/models/purchase_order.py +++ b/jikimo_purchase_request/models/purchase_order.py @@ -16,6 +16,69 @@ class PurchaseOrder(models.Model): ('rejected', '已驳回') ], string='Status', readonly=True, index=True, copy=False, default='draft', tracking=True) + # 成品采购订单对应的坯料采购申请单和采购订单数量 + purchase_request_count = fields.Integer('子·采购申请数量', compute='_compute_purchase_request') + purchase_order_count = fields.Integer('子·采购订单数量', compute='_compute_purchase_request') + + @api.depends('state') + def _compute_purchase_request(self): + for record in self: + purchase_request_ids, purchase_order_ids = record.get_purchase_request_order() + record.purchase_request_count = len(purchase_request_ids) + record.purchase_order_count = len(purchase_order_ids) + + def action_view_preform_body_purchase_request(self): + self.ensure_one() + name_list = self._get_pinking_name() + purchase_request_ids = self.env['purchase.request'].search([('origin', 'in', name_list)]) + + action = { + 'res_model': 'purchase.request', + 'type': 'ir.actions.act_window', + } + if len(purchase_request_ids) == 1: + action.update({ + 'view_mode': 'form', + 'res_id': purchase_request_ids[0].id, + }) + else: + action.update({ + 'name': _("子·采购申请"), + 'domain': [('id', 'in', purchase_request_ids.ids)], + 'view_mode': 'tree,form', + }) + return action + + def action_view_preform_body_purchase_order(self): + self.ensure_one() + name_list = self._get_pinking_name() + purchase_order_ids = self.env['purchase.order'].search([('origin', 'in', name_list)]) + + action = { + 'res_model': 'purchase.order', + 'type': 'ir.actions.act_window', + } + if len(purchase_order_ids) == 1: + action.update({ + 'view_mode': 'form', + 'res_id': purchase_order_ids[0].id, + }) + else: + action.update({ + 'name': _("子·采购订单"), + 'domain': [('id', 'in', purchase_order_ids.ids)], + 'view_mode': 'tree,form', + }) + return action + + def get_purchase_request_order(self): + name_list = self._get_pinking_name() + purchase_request_ids = self.env['purchase.request'].search([('origin', 'in', name_list)]) + purchase_order_ids = self.env['purchase.order'].search([('origin', 'in', name_list)]) + return purchase_request_ids, purchase_order_ids + + def _get_pinking_name(self): + return [picking_id.name for picking_id in self.picking_ids if picking_id.name] def button_confirm(self): res = super(PurchaseOrder, self).button_confirm() diff --git a/jikimo_purchase_request/views/purchase_order.xml b/jikimo_purchase_request/views/purchase_order.xml new file mode 100644 index 00000000..78f5b6a8 --- /dev/null +++ b/jikimo_purchase_request/views/purchase_order.xml @@ -0,0 +1,28 @@ + + + + purchase.order.inherited.form.jikimo.purchase.request + purchase.order + + + + + + + + + \ No newline at end of file