From 1a9094fa24f9a4b35adc82f151d85877d7df58fb Mon Sep 17 00:00:00 2001 From: Bhavesh Odedra Date: Thu, 8 Mar 2018 18:16:45 +0530 Subject: [PATCH] [IMP] wizard button standard & QTY readonly if no access --- .../models/stock_warehouse_orderpoint.py | 8 ++++ .../wizards/make_procurement_orderpoint.py | 22 +++++++--- .../make_procurement_orderpoint_view.xml | 44 ++++++++++++++++--- 3 files changed, 62 insertions(+), 12 deletions(-) diff --git a/stock_orderpoint_manual_procurement/models/stock_warehouse_orderpoint.py b/stock_orderpoint_manual_procurement/models/stock_warehouse_orderpoint.py index eeb675e1f..433841b3c 100644 --- a/stock_orderpoint_manual_procurement/models/stock_warehouse_orderpoint.py +++ b/stock_orderpoint_manual_procurement/models/stock_warehouse_orderpoint.py @@ -24,6 +24,14 @@ class StockWarehouseOrderpoint(models.Model): compute="_compute_procure_recommended", ) + def _prepare_procurement_values(self, product_qty, date=False, + group=False): + res = super(StockWarehouseOrderpoint, + self)._prepare_procurement_values(product_qty, date=date, + group=group) + res.update({'qty': product_qty}) + return res + @api.multi def _get_procure_recommended_qty(self, virtual_qty, op_qtys): self.ensure_one() diff --git a/stock_orderpoint_manual_procurement/wizards/make_procurement_orderpoint.py b/stock_orderpoint_manual_procurement/wizards/make_procurement_orderpoint.py index 321a59ca4..adfce8a44 100644 --- a/stock_orderpoint_manual_procurement/wizards/make_procurement_orderpoint.py +++ b/stock_orderpoint_manual_procurement/wizards/make_procurement_orderpoint.py @@ -18,6 +18,7 @@ class MakeProcurementOrderpoint(models.TransientModel): def _prepare_item(self, orderpoint): return { 'qty': orderpoint.procure_recommended_qty, + 'qty_without_security': orderpoint.procure_recommended_qty, 'uom_id': orderpoint.product_uom.id, 'orderpoint_id': orderpoint.id, 'product_id': orderpoint.product_id.id, @@ -25,6 +26,18 @@ class MakeProcurementOrderpoint(models.TransientModel): 'location_id': orderpoint.location_id.id } + @api.model + def fields_view_get(self, view_id=None, view_type='form', toolbar=False, + submenu=False): + if not self.user_has_groups( + "stock_orderpoint_manual_procurement.group_change_orderpoint_procure_qty"): # noqa + # Redirect to readonly qty form view + view_id = self.env.ref( + 'stock_orderpoint_manual_procurement.view_make_procure_without_security').id # noqa + return super(MakeProcurementOrderpoint, self).fields_view_get( + view_id=view_id, view_type=view_type, toolbar=toolbar, + submenu=submenu) + @api.model def default_get(self, fields): res = super(MakeProcurementOrderpoint, self).default_get(fields) @@ -57,7 +70,7 @@ class MakeProcurementOrderpoint(models.TransientModel): try: self.env['procurement.group'].run( item.orderpoint_id.product_id, - item.qty, + values.get('qty'), item.orderpoint_id.product_uom, item.orderpoint_id.location_id, item.orderpoint_id.name, @@ -68,7 +81,6 @@ class MakeProcurementOrderpoint(models.TransientModel): errors.append(error.name) if errors: raise UserError('\n'.join(errors)) - return {'type': 'ir.actions.act_window_close'} @@ -80,7 +92,8 @@ class MakeProcurementOrderpointItem(models.TransientModel): 'make.procurement.orderpoint', string='Wizard', required=True, ondelete='cascade', readonly=True) - qty = fields.Float(string='Quantity', required=True) + qty = fields.Float(string='Quantity') + qty_without_security = fields.Float(string='Quantity') uom_id = fields.Many2one(string='Unit of Measure', comodel_name='product.uom') @@ -104,5 +117,4 @@ class MakeProcurementOrderpointItem(models.TransientModel): def onchange_uom_id(self): for rec in self: rec.qty = rec.orderpoint_id.product_uom._compute_quantity( - rec.orderpoint_id.procure_recommended_qty, - rec.uom_id) + rec.orderpoint_id.procure_recommended_qty, rec.uom_id) diff --git a/stock_orderpoint_manual_procurement/wizards/make_procurement_orderpoint_view.xml b/stock_orderpoint_manual_procurement/wizards/make_procurement_orderpoint_view.xml index 252650eef..be85ec02e 100644 --- a/stock_orderpoint_manual_procurement/wizards/make_procurement_orderpoint_view.xml +++ b/stock_orderpoint_manual_procurement/wizards/make_procurement_orderpoint_view.xml @@ -1,8 +1,7 @@ - - + Request Procurement make.procurement.orderpoint @@ -21,21 +20,52 @@ - + +
-
+ + + Request Procurement + make.procurement.orderpoint + +
+

+ Use this assistant to generate a procurement request for this + stock buffer. According to the product configuration, + this may trigger a draft purchase order, a manufacturing + order or a transfer picking. +

+ + + + + + + + + + + + + +
+
+
+
+