| 
						
						
							
								
							
						
						
					 | 
					@ -26,32 +26,25 @@ from odoo import models, fields, api, _ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					class InvoiceStockMove(models.Model): | 
					 | 
					 | 
					class InvoiceStockMove(models.Model): | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    _inherit = 'account.move' | 
					 | 
					 | 
					    _inherit = 'account.move' | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					    @api.model | 
					 | 
					 | 
					    def _get_stock_type_ids(self): | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    def _default_picking_receive(self): | 
					 | 
					 | 
					        data = self.env['stock.picking.type'].search([]) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        type_obj = self.env['stock.picking.type'] | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        company_id = self.env.context.get('company_id') or self.env.user.company_id.id | 
					 | 
					 | 
					        if self._context.get('default_type') == 'out_invoice': | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        types = type_obj.search([('code', '=', 'incoming'), ('warehouse_id.company_id', '=', company_id)], limit=1) | 
					 | 
					 | 
					            for line in data: | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        if not types: | 
					 | 
					 | 
					                if line.code == 'outgoing': | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            types = type_obj.search([('code', '=', 'incoming'), ('warehouse_id', '=', False)]) | 
					 | 
					 | 
					                    return line | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					        return types[:1] | 
					 | 
					 | 
					        if self._context.get('default_type') == 'in_invoice': | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					
 | 
					 | 
					 | 
					            for line in data: | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    @api.model | 
					 | 
					 | 
					                if line.code == 'incoming': | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					    def _default_picking_transfer(self): | 
					 | 
					 | 
					                    return line | 
				
			
			
				
				
			
		
	
		
		
			
				
					 | 
					 | 
					        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] | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    picking_count = fields.Integer(string="Count") | 
					 | 
					 | 
					    picking_count = fields.Integer(string="Count") | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    invoice_picking_id = fields.Many2one('stock.picking', string="Picking Id") | 
					 | 
					 | 
					    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") | 
					 | 
					 | 
					                                      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([ | 
					 | 
					 | 
					    state = fields.Selection([ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        ('draft', 'Draft'), | 
					 | 
					 | 
					        ('draft', 'Draft'), | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        ('proforma', 'Pro-forma'), | 
					 | 
					 | 
					        ('proforma', 'Pro-forma'), | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -65,6 +58,10 @@ class InvoiceStockMove(models.Model): | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    def action_stock_move(self): | 
					 | 
					 | 
					    def action_stock_move(self): | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        for order in 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: | 
					 | 
					 | 
					            if not self.invoice_picking_id: | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                pick = { | 
					 | 
					 | 
					                pick = { | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    'picking_type_id': self.picking_type_id.id, | 
					 | 
					 | 
					                    'picking_type_id': self.picking_type_id.id, | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -76,7 +73,8 @@ class InvoiceStockMove(models.Model): | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                picking = self.env['stock.picking'].create(pick) | 
					 | 
					 | 
					                picking = self.env['stock.picking'].create(pick) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                self.invoice_picking_id = picking.id | 
					 | 
					 | 
					                self.invoice_picking_id = picking.id | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                self.picking_count = len(picking) | 
					 | 
					 | 
					                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 = moves._action_confirm() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                move_ids._action_assign() | 
					 | 
					 | 
					                move_ids._action_assign() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -93,6 +91,33 @@ class InvoiceStockMove(models.Model): | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            result['res_id'] = pick_ids or False | 
					 | 
					 | 
					            result['res_id'] = pick_ids or False | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        return result | 
					 | 
					 | 
					        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): | 
					 | 
					 | 
					class SupplierInvoiceLine(models.Model): | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    _inherit = 'account.move.line' | 
					 | 
					 | 
					    _inherit = 'account.move.line' | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -109,12 +134,10 @@ class SupplierInvoiceLine(models.Model): | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                'location_id': line.move_id.partner_id.property_stock_supplier.id, | 
					 | 
					 | 
					                'location_id': line.move_id.partner_id.property_stock_supplier.id, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                'location_dest_id': picking.picking_type_id.default_location_dest_id.id, | 
					 | 
					 | 
					                'location_dest_id': picking.picking_type_id.default_location_dest_id.id, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                'picking_id': picking.id, | 
					 | 
					 | 
					                'picking_id': picking.id, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                # 'move_dest_id': False, | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                'state': 'draft', | 
					 | 
					 | 
					                'state': 'draft', | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                'company_id': line.move_id.company_id.id, | 
					 | 
					 | 
					                'company_id': line.move_id.company_id.id, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                'price_unit': price_unit, | 
					 | 
					 | 
					                'price_unit': price_unit, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                'picking_type_id': picking.picking_type_id.id, | 
					 | 
					 | 
					                'picking_type_id': picking.picking_type_id.id, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                # 'procurement_id': False, | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                'route_ids': 1 and [ | 
					 | 
					 | 
					                'route_ids': 1 and [ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    (6, 0, [x.id for x in self.env['stock.location.route'].search([('id', 'in', (2, 3))])])] or [], | 
					 | 
					 | 
					                    (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, | 
					 | 
					 | 
					                'warehouse_id': picking.picking_type_id.warehouse_id.id, | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					
  |