diff --git a/bahmni_stock/__init__.py b/bahmni_stock/__init__.py index 7db6694..fc07b72 100644 --- a/bahmni_stock/__init__.py +++ b/bahmni_stock/__init__.py @@ -1,3 +1,4 @@ # -*- coding: utf-8 -*- from . import models from . import report +from . import wizard diff --git a/bahmni_stock/__manifest__.py b/bahmni_stock/__manifest__.py index 872333c..0bb1f28 100644 --- a/bahmni_stock/__manifest__.py +++ b/bahmni_stock/__manifest__.py @@ -12,10 +12,12 @@ 'website': '', 'images': [], 'depends': ['stock', 'bahmni_product'], - 'data': ['views/stock_production_lot_view.xml', + 'data': ['security/ir.model.access.csv', + 'views/stock_production_lot_view.xml', 'views/stock_picking_view.xml', 'views/account_invoice_line.xml', 'views/stock_pick_lot_view.xml', + 'wizard/stock_picking_validate_wizard.xml', ], 'demo': [], 'qweb': [], diff --git a/bahmni_stock/models/stock_picking.py b/bahmni_stock/models/stock_picking.py index e455a45..2a3bbdf 100644 --- a/bahmni_stock/models/stock_picking.py +++ b/bahmni_stock/models/stock_picking.py @@ -1,23 +1,34 @@ # -*- coding: utf-8 -*- from collections import namedtuple -from odoo import fields, models, api +from odoo import fields, models, api, _ from odoo.tools.float_utils import float_compare from odoo.exceptions import UserError from odoo.exceptions import UserError, ValidationError, AccessError, RedirectWarning +import logging + +_logger = logging.getLogger(__name__) + class StockPicking(models.Model): _inherit = 'stock.picking' + STOCK_PICKING_CODE_INTERNAL = 'internal' + STOCK_PICKING_CODE_INCOMING = 'incoming' + STOCK_PICKING_NAME_PURCHASE = 'Receipts' + def button_validate(self): self.validate_batch_quantity_for_internal_transfer() - res = super(StockPicking, self).button_validate() - self.update_price_details_for_lots() - return res + if self._is_validation_needed(): + return self.show_validation_screen() + else: + res = super(StockPicking, self).button_validate() + self.update_price_details_for_lots() + return res def validate_batch_quantity_for_internal_transfer(self): - if self.picking_type_id and self.picking_type_id.code == 'internal': + if self.picking_type_id and self.picking_type_id.code == self.STOCK_PICKING_CODE_INTERNAL: for line in self.move_line_ids: if line.product_id.tracking != 'none': stock_quant_lot = self.env['stock.quant'].search([ @@ -27,8 +38,26 @@ def validate_batch_quantity_for_internal_transfer(self): raise UserError("Insufficient batch(%s) quantity for %s and available quantity is %s" \ %(line.lot_id.name, line.product_id.name, stock_quant_lot.quantity)) + def show_validation_screen(self): + view_id = self.env.ref('bahmni_stock.stock_picking_validate_wizard_view').id + context = dict(self.env.context) + context.update({ + 'default_move_lines': [(6, 0, self.move_line_ids.filtered(lambda line: line.qty_done > 0).ids)], + 'default_picking_id': self.id + }) + return { + 'name': _('Validate Stock Entries'), + 'type': 'ir.actions.act_window', + 'res_model': 'stock.picking.validate.wizard', + 'view_mode': 'form', + 'views': [(view_id, 'form')], + 'view_id': view_id, + 'target': 'new', + 'context': context, + } def update_price_details_for_lots(self): - if self.picking_type_id and self.picking_type_id.code == 'incoming' and self.picking_type_id.name == 'Receipts': + if self.picking_type_id and self.picking_type_id.code == self.STOCK_PICKING_CODE_INCOMING\ + and self.picking_type_id.name == self.STOCK_PICKING_NAME_PURCHASE: for line in self.move_line_ids: if line.product_id.tracking != 'none': line.lot_id.cost_price = line.cost_price @@ -36,6 +65,14 @@ def update_price_details_for_lots(self): line.lot_id.mrp = line.mrp line.lot_id.expiration_date = line.expiration_date + def _is_validation_needed(self): + if self.env.context.get('validation_confirmed'): + return False + if self.picking_type_id.code in [self.STOCK_PICKING_CODE_INTERNAL, self.STOCK_PICKING_CODE_INCOMING]: + return True + return False + + # this method is overridden to update cost_price, sale_price and mrp while lot is getting created def _create_lots_for_picking(self): Lot = self.env['stock.production.lot'] diff --git a/bahmni_stock/security/ir.model.access.csv b/bahmni_stock/security/ir.model.access.csv index 240a24b..b2dd4ed 100644 --- a/bahmni_stock/security/ir.model.access.csv +++ b/bahmni_stock/security/ir.model.access.csv @@ -1,3 +1,2 @@ id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink -stock_batch_future_forecast_user,Stock Batch Future Forecast Stock User,model_batch_stock_future_forecast,stock.group_stock_user,1,1,1,0 -stock_report_prod_by_last_moved_user,Stock Report Products by Last Moved Stock User,model_prod_last_moved_report,stock.group_stock_user,1,1,1,0 +access_stock_picking_validation,access_stock_picking_validation,model_stock_picking_validate_wizard,,1,1,1,1 diff --git a/bahmni_stock/wizard/__init__.py b/bahmni_stock/wizard/__init__.py new file mode 100644 index 0000000..f926e5f --- /dev/null +++ b/bahmni_stock/wizard/__init__.py @@ -0,0 +1 @@ +from . import stock_picking_validate_wizard diff --git a/bahmni_stock/wizard/stock_picking_validate_wizard.py b/bahmni_stock/wizard/stock_picking_validate_wizard.py new file mode 100644 index 0000000..c164a37 --- /dev/null +++ b/bahmni_stock/wizard/stock_picking_validate_wizard.py @@ -0,0 +1,21 @@ +from odoo import api, fields, models, _ + +import logging + +_logger = logging.getLogger(__name__) + + +class StockPickingValidateWizard(models.TransientModel): + _name = 'stock.picking.validate.wizard' + _description = 'Validation Wizard for Stock Picking Operations' + + move_lines = fields.Many2many('stock.move.line', readonly=True) + picking_id = fields.Many2one('stock.picking', 'Picking') + picking_code = fields.Selection(related='picking_id.picking_type_id.code', readonly=True) + source_location = fields.Many2one('stock.location', related='picking_id.location_id', string="Source Location", + readonly=True) + destination_location = fields.Many2one('stock.location', related='picking_id.location_dest_id', + string="Destination Location", readonly=True) + + def btn_confirm(self): + return self.picking_id.with_context(validation_confirmed=True).button_validate() diff --git a/bahmni_stock/wizard/stock_picking_validate_wizard.xml b/bahmni_stock/wizard/stock_picking_validate_wizard.xml new file mode 100644 index 0000000..0187fad --- /dev/null +++ b/bahmni_stock/wizard/stock_picking_validate_wizard.xml @@ -0,0 +1,54 @@ + + + + Validate Stock Picking + stock.picking.validate.wizard + +
+ + +
+
+
+
+
+
+
+ + + + + + + + + /> + + + + + + + +
+
+