From e470cf945f2d98410d79a4273b62bd98b07d0ff1 Mon Sep 17 00:00:00 2001 From: Pratima Gupta Date: Mon, 25 Jan 2021 04:55:03 +0000 Subject: [PATCH] [IMP] purchase_stock, mrp: improved the log note of replenishment report mrp - when a MO is generated from replenishment report, a log note is added to chatter with the link of replenishment report, as this report got deleted when to to qty is 0.0 then link dost not work. Hence added the simple text for Relenishment report. purchase_stock - When click on the order once button of replenishment report, if vendor is not added on product then, added a new wizard with functionality to directly jump on the edit product. Added log note to the PO if po lines are generated through the Replenishment report. TaskId - 2427738 [IMP] stock: split method to create new or unlink unused OP As, server action was added to the Replenishment menu, unless until user clicks on the menu, new order point will not get generate. Hence splitted the method and added to auto vaccum for this. TaskId - 2427738 closes odoo/odoo#66130 Signed-off-by: Arnold Moyaux --- addons/mrp/models/stock_rule.py | 23 ++++++++++------ addons/stock/models/stock_orderpoint.py | 35 +++++++++++++++++++++---- 2 files changed, 45 insertions(+), 13 deletions(-) diff --git a/addons/mrp/models/stock_rule.py b/addons/mrp/models/stock_rule.py index fc2bb6125ae..f60036cd4d3 100644 --- a/addons/mrp/models/stock_rule.py +++ b/addons/mrp/models/stock_rule.py @@ -60,14 +60,21 @@ class StockRule(models.Model): 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: - production.message_post_with_view('mail.message_origin_link', - values={'self': production, 'origin': orderpoint}, - subtype_id=self.env.ref('mail.mt_note').id) - if 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) + 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 _get_custom_move_fields(self): diff --git a/addons/stock/models/stock_orderpoint.py b/addons/stock/models/stock_orderpoint.py index 0d16e1468ef..f70a104da91 100644 --- a/addons/stock/models/stock_orderpoint.py +++ b/addons/stock/models/stock_orderpoint.py @@ -10,7 +10,7 @@ from psycopg2 import OperationalError from odoo import SUPERUSER_ID, _, api, fields, models, registry from odoo.addons.stock.models.stock_rule import ProcurementException -from odoo.exceptions import UserError, ValidationError +from odoo.exceptions import RedirectWarning, UserError, ValidationError from odoo.osv import expression from odoo.tools import add, float_compare, frozendict, split_every @@ -206,7 +206,19 @@ class StockWarehouseOrderpoint(models.Model): return action def action_replenish(self): - self._procure_orderpoint_confirm(company_id=self.env.company) + try: + self._procure_orderpoint_confirm(company_id=self.env.company) + except UserError as e: + if len(self) != 1: + raise e + raise RedirectWarning(e, { + 'name': self.product_id.display_name, + 'type': 'ir.actions.act_window', + 'res_model': 'product.product', + 'res_id': self.product_id.id, + 'views': [(self.env.ref('product.product_normal_form_view').id, 'form')], + 'context': {'form_view_initial_mode': 'edit'} + }, _('Edit Product')) notification = False if len(self) == 1: notification = self._get_replenishment_order_notification() @@ -307,9 +319,8 @@ class StockWarehouseOrderpoint(models.Model): # In master: the active field should be remove orderpoints = self.env['stock.warehouse.orderpoint'].with_context(active_test=False).search([]) # Remove previous automatically created orderpoint that has been refilled. - to_remove = orderpoints.filtered(lambda o: o.create_uid.id == SUPERUSER_ID and o.qty_to_order <= 0.0 and o.trigger == 'manual') - to_remove.unlink() - orderpoints = orderpoints - to_remove + orderpoints_removed = orderpoints._unlink_processed_orderpoints() + orderpoints = orderpoints - orderpoints_removed to_refill = defaultdict(float) all_product_ids = [] all_warehouse_ids = [] @@ -435,6 +446,20 @@ class StockWarehouseOrderpoint(models.Model): (example: purchases created from orderpoints)""" return dict(self.mapped(lambda x: (x.id, 0.0))) + @api.autovacuum + def _unlink_processed_orderpoints(self): + domain = [ + ('create_uid', '=', SUPERUSER_ID), + ('trigger', '=', 'manual'), + ('qty_to_order', '<=', 0) + ] + if self.ids: + expression.AND([domain, [('ids', 'in', self.ids)]]) + orderpoints_to_remove = self.env['stock.warehouse.orderpoint'].with_context(active_test=False).search(domain) + # Remove previous automatically created orderpoint that has been refilled. + orderpoints_to_remove.unlink() + return orderpoints_to_remove + def _prepare_procurement_values(self, date=False, group=False): """ Prepare specific key for moves or other components that will be created from a stock rule comming from an orderpoint. This method could be override in order to add other custom key that could