From c8014276ec9210fc6442f55db835e5d0d1eb4bf5 Mon Sep 17 00:00:00 2001 From: Ajmal JK Date: Mon, 20 Jan 2020 09:20:04 +0530 Subject: [PATCH] [FIX] Bug Fixed 'invoice_stock_move' --- invoice_stock_move/__manifest__.py | 4 +- invoice_stock_move/doc/RELEASE_NOTES.md | 6 ++ invoice_stock_move/models/invoice_stock.py | 73 ++++++++++++------- .../views/invoice_stock_move_view.xml | 50 +++++++------ 4 files changed, 82 insertions(+), 51 deletions(-) diff --git a/invoice_stock_move/__manifest__.py b/invoice_stock_move/__manifest__.py index ed7785e17..8ff74036a 100644 --- a/invoice_stock_move/__manifest__.py +++ b/invoice_stock_move/__manifest__.py @@ -21,14 +21,14 @@ ############################################################################# { 'name': "Stock Picking From Invoice", - 'version': '13.0.1.0.0', + 'version': '13.0.1.1.1', 'summary': """Stock Picking From Customer/Supplier Invoice""", 'description': """This Module Enables To Create Stocks Picking From Customer/Supplier Invoice""", 'author': "Cybrosys Techno Solutions", 'company': 'Cybrosys Techno Solutions', 'website': "https://www.cybrosys.com", 'category': 'Accounting', - 'depends': ['base', 'account', 'stock'], + 'depends': ['base', 'account', 'stock', 'payment'], 'data': ['views/invoice_stock_move_view.xml'], 'images': ['static/description/banner.jpg'], 'license': 'AGPL-3', diff --git a/invoice_stock_move/doc/RELEASE_NOTES.md b/invoice_stock_move/doc/RELEASE_NOTES.md index 39878fa46..f46694734 100644 --- a/invoice_stock_move/doc/RELEASE_NOTES.md +++ b/invoice_stock_move/doc/RELEASE_NOTES.md @@ -5,3 +5,9 @@ #### ADD Initial Commit + +#### 17.01.2020 +#### Version 13.0.1.1.1 +#### FIX + +Delivery and Receipts Bug fixed. diff --git a/invoice_stock_move/models/invoice_stock.py b/invoice_stock_move/models/invoice_stock.py index 632592c8c..04734456c 100644 --- a/invoice_stock_move/models/invoice_stock.py +++ b/invoice_stock_move/models/invoice_stock.py @@ -26,32 +26,25 @@ from odoo import models, fields, api, _ class InvoiceStockMove(models.Model): _inherit = 'account.move' - @api.model - def _default_picking_receive(self): - type_obj = self.env['stock.picking.type'] - company_id = self.env.context.get('company_id') or self.env.user.company_id.id - types = type_obj.search([('code', '=', 'incoming'), ('warehouse_id.company_id', '=', company_id)], limit=1) - if not types: - types = type_obj.search([('code', '=', 'incoming'), ('warehouse_id', '=', False)]) - return types[:1] - - @api.model - def _default_picking_transfer(self): - type_obj = self.env['stock.picking.type'] - company_id = self.env.context.get('company_id') or self.env.user.company_id.id - types = type_obj.search([('code', '=', 'outgoing'), ('warehouse_id.company_id', '=', company_id)], limit=1) - if not types: - types = type_obj.search([('code', '=', 'outgoing'), ('warehouse_id', '=', False)]) - return types[:4] + def _get_stock_type_ids(self): + data = self.env['stock.picking.type'].search([]) + + if self._context.get('default_type') == 'out_invoice': + for line in data: + if line.code == 'outgoing': + return line + if self._context.get('default_type') == 'in_invoice': + for line in data: + if line.code == 'incoming': + return line picking_count = fields.Integer(string="Count") invoice_picking_id = fields.Many2one('stock.picking', string="Picking Id") - picking_type_id = fields.Many2one('stock.picking.type', 'Picking Type', required=True, - default=_default_picking_receive, + + picking_type_id = fields.Many2one('stock.picking.type', 'Picking Type', + default=_get_stock_type_ids, help="This will determine picking type of incoming shipment") - picking_transfer_id = fields.Many2one('stock.picking.type', 'Deliver To', required=True, - default=_default_picking_transfer, - help="This will determine picking type of outgoing shipment") + state = fields.Selection([ ('draft', 'Draft'), ('proforma', 'Pro-forma'), @@ -65,6 +58,10 @@ class InvoiceStockMove(models.Model): def action_stock_move(self): for order in self: + if not self.picking_type_id.default_location_dest_id: + raise UserError(_( + " Please set Default Destination Location")) + if not self.invoice_picking_id: pick = { 'picking_type_id': self.picking_type_id.id, @@ -76,7 +73,8 @@ class InvoiceStockMove(models.Model): picking = self.env['stock.picking'].create(pick) self.invoice_picking_id = picking.id self.picking_count = len(picking) - moves = order.invoice_line_ids.filtered(lambda r: r.product_id.type in ['product', 'consu'])._create_stock_moves(picking) + moves = order.invoice_line_ids.filtered( + lambda r: r.product_id.type in ['product', 'consu'])._create_stock_moves(picking) move_ids = moves._action_confirm() move_ids._action_assign() @@ -93,6 +91,33 @@ class InvoiceStockMove(models.Model): result['res_id'] = pick_ids or False return result + def action_post(self): + if not self.picking_type_id: + raise UserError(_( + " Please select a picking type")) + res = super(InvoiceStockMove, self).action_post() + return res + + def _reverse_moves(self, default_values_list=None, cancel=False): + ''' Reverse a recordset of account.move. + If cancel parameter is true, the reconcilable or liquidity lines + of each original move will be reconciled with its reverse's. + + :param default_values_list: A list of default values to consider per move. + ('type' & 'reversed_entry_id' are computed in the method). + :return: An account.move recordset, reverse of the current self. + ''' + print("Reverse moves", self.picking_type_id) + + if self.picking_type_id.code == 'outgoing': + data = self.env['stock.picking.type'].search([('company_id', '=', self.company_id.id),('code', '=', 'incoming')], limit=1) + self.picking_type_id = data.id + elif self.picking_type_id.code == 'incoming': + data = self.env['stock.picking.type'].search([('company_id', '=', self.company_id.id),('code', '=', 'outgoing')], limit=1) + self.picking_type_id = data.id + reverse_moves = super(InvoiceStockMove, self)._reverse_moves() + return reverse_moves + class SupplierInvoiceLine(models.Model): _inherit = 'account.move.line' @@ -109,12 +134,10 @@ class SupplierInvoiceLine(models.Model): 'location_id': line.move_id.partner_id.property_stock_supplier.id, 'location_dest_id': picking.picking_type_id.default_location_dest_id.id, 'picking_id': picking.id, - # 'move_dest_id': False, 'state': 'draft', 'company_id': line.move_id.company_id.id, 'price_unit': price_unit, 'picking_type_id': picking.picking_type_id.id, - # 'procurement_id': False, 'route_ids': 1 and [ (6, 0, [x.id for x in self.env['stock.location.route'].search([('id', 'in', (2, 3))])])] or [], 'warehouse_id': picking.picking_type_id.warehouse_id.id, diff --git a/invoice_stock_move/views/invoice_stock_move_view.xml b/invoice_stock_move/views/invoice_stock_move_view.xml index 3beea0ebd..5dcb03cec 100644 --- a/invoice_stock_move/views/invoice_stock_move_view.xml +++ b/invoice_stock_move/views/invoice_stock_move_view.xml @@ -2,29 +2,31 @@ - Move Name - account.move - - - - - - - + Move Name + account.move + + + + + + + - + \ No newline at end of file