| 
						
						
							
								
							
						
						
					 | 
					@ -25,7 +25,6 @@ from collections import defaultdict | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					from odoo.exceptions import UserError | 
					 | 
					 | 
					from odoo.exceptions import UserError | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					class StockLandedCost(models.Model): | 
					 | 
					 | 
					class StockLandedCost(models.Model): | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    """Inherits 'stock.landed.cost' model to add additional functionality | 
					 | 
					 | 
					    """Inherits 'stock.landed.cost' model to add additional functionality | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    related to cancelling and resetting landed cost records. | 
					 | 
					 | 
					    related to cancelling and resetting landed cost records. | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
							
								
							
						
						
					 | 
					@ -83,12 +82,13 @@ class StockLandedCost(models.Model): | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                # batch standard price computation avoid recompute quantity_svl at each iteration | 
					 | 
					 | 
					                # batch standard price computation avoid recompute quantity_svl at each iteration | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                products = self.env['product.product'].browse(p.id for p in cost_to_add_byproduct.keys()).with_company( | 
					 | 
					 | 
					                products = self.env['product.product'].browse(p.id for p in cost_to_add_byproduct.keys()).with_company( | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    cost.company_id) | 
					 | 
					 | 
					                    cost.company_id) | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					                for product in products:  # iterate on recordset to prefetch efficiently quantity_svl | 
					 | 
					 | 
					                for product in products: | 
				
			
			
				
				
			
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					                    if not float_is_zero(product.quantity_svl, precision_rounding=product.uom_id.rounding): | 
					 | 
					 | 
					                    if not float_is_zero(product.quantity_svl, precision_rounding=product.uom_id.rounding): | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                        product.sudo().with_context(disable_auto_svl=True).standard_price += cost_to_add_byproduct[ | 
					 | 
					 | 
					                        product.sudo().with_context(disable_auto_svl=True).standard_price += cost_to_add_byproduct[ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                                                                                                 product] / product.quantity_svl | 
					 | 
					 | 
					                                                                                                 product] / product.quantity_svl | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    def action_landed_cost_cancel(self): | 
					 | 
					 | 
					    def action_landed_cost_cancel(self): | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        print('action_landed_cost_cancel') | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        """Cancels the landed cost record by deleting its associated | 
					 | 
					 | 
					        """Cancels the landed cost record by deleting its associated | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        accounting entries, stock valuation, and changes state to 'cancelled'. | 
					 | 
					 | 
					        accounting entries, stock valuation, and changes state to 'cancelled'. | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -96,26 +96,51 @@ class StockLandedCost(models.Model): | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					         entries, which are also deleted in the process. | 
					 | 
					 | 
					         entries, which are also deleted in the process. | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        """ | 
					 | 
					 | 
					        """ | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        for rec in self: | 
					 | 
					 | 
					        for rec in self: | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            print('rec', rec) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            for line in rec.valuation_adjustment_lines.filtered( | 
					 | 
					 | 
					            for line in rec.valuation_adjustment_lines.filtered( | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    lambda line: line.move_id): | 
					 | 
					 | 
					                    lambda line: line.move_id): | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                product = line.move_id.product_id | 
					 | 
					 | 
					                product = line.move_id.product_id | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                if product.cost_method == 'average': | 
					 | 
					 | 
					                if product.cost_method == 'average': | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    self.calculate_avco_price() | 
					 | 
					 | 
					                    self.calculate_avco_price() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					            if rec.account_move_id: | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                account_id = rec.account_move_id | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                account_move_ids = account_id.line_ids | 
					 | 
					 | 
					            if rec.vendor_bill_id and rec.vendor_bill_id.mapped('line_ids'): | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                if account_move_ids: | 
					 | 
					 | 
					                rec.vendor_bill_id.button_draft() | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    account_id.sudo().write( | 
					 | 
					 | 
					                rec.vendor_bill_id.sudo().write( | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                        {'state': 'draft', 'name': 'Delete Sequence Number'}) | 
					 | 
					 | 
					                    {'name': 'Delete Sequence Number'}) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    account_move_ids.sudo().unlink() | 
					 | 
					 | 
					                landed_cost_line = rec.vendor_bill_id.mapped('line_ids').filtered( | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    account_id.sudo().unlink() | 
					 | 
					 | 
					                    lambda x: x.is_landed_costs_line is True) | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                if landed_cost_line : | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                    landed_cost_line.unlink() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                if rec.valuation_adjustment_lines: | 
					 | 
					 | 
					                if rec.valuation_adjustment_lines: | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    rec.valuation_adjustment_lines.unlink() | 
					 | 
					 | 
					                    rec.valuation_adjustment_lines.unlink() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					            if rec.stock_valuation_layer_ids: | 
					 | 
					 | 
					                for layer in rec.stock_valuation_layer_ids: | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                rec.stock_valuation_layer_ids.sudo().unlink() | 
					 | 
					 | 
					                    rec.env['stock.valuation.layer.revaluation'].create([{ | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                        'product_id': layer.product_id.id, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                        'company_id': layer.company_id.id, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                        'added_value': - layer.value | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                    }]).action_validate_revaluation() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                rec.write({'state': 'cancel'}) | 
					 | 
					 | 
					                rec.write({'state': 'cancel'}) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            # if rec.account_move_id: | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #     print('journal') | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #     account_id = rec.account_move_id | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #     print('account_id',account_id) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #     account_move_ids = account_id.line_ids | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #     print('account_move_ids',account_move_ids) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #     if account_move_ids: | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #         print('if account_move_ids') | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #         account_id.sudo().write( | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #             {'state': 'draft', 'name': 'Delete Sequence Number'}) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #         print('account_id2',account_id) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #         account_move_ids.sudo().unlink() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #         account_id.sudo().unlink() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    def action_landed_cost_reset_and_cancel(self): | 
					 | 
					 | 
					    def action_landed_cost_reset_and_cancel(self): | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        """Resets the landed cost record by deleting its associated accounting | 
					 | 
					 | 
					        """Resets the landed cost record by deleting its associated accounting | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        entries and stock valuation. It changes the state back to 'draft'. | 
					 | 
					 | 
					        entries and stock valuation. It changes the state back to 'draft'. | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -130,18 +155,22 @@ class StockLandedCost(models.Model): | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                if product.cost_method == 'average': | 
					 | 
					 | 
					                if product.cost_method == 'average': | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    self.calculate_avco_price() | 
					 | 
					 | 
					                    self.calculate_avco_price() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					            if rec.account_move_id: | 
					 | 
					 | 
					            if rec.vendor_bill_id and rec.vendor_bill_id.mapped('line_ids'): | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                account_id = rec.account_move_id | 
					 | 
					 | 
					                rec.vendor_bill_id.button_draft() | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                account_move_ids = account_id.line_ids | 
					 | 
					 | 
					                rec.vendor_bill_id.sudo().write( | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                if account_move_ids: | 
					 | 
					 | 
					                    {'name': 'Delete Sequence Number'}) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    account_id.sudo().write( | 
					 | 
					 | 
					                landed_cost_line = rec.vendor_bill_id.mapped('line_ids').filtered( | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                        {'state': 'draft', 'name': 'Delete Sequence Number'}) | 
					 | 
					 | 
					                    lambda x: x.is_landed_costs_line is True) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    account_move_ids.sudo().unlink() | 
					 | 
					 | 
					                if landed_cost_line: | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    account_id.sudo().unlink() | 
					 | 
					 | 
					                    landed_cost_line.unlink() | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					                if rec.valuation_adjustment_lines: | 
					 | 
					 | 
					                if rec.valuation_adjustment_lines: | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    rec.valuation_adjustment_lines.unlink() | 
					 | 
					 | 
					                    rec.valuation_adjustment_lines.unlink() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					            if rec.stock_valuation_layer_ids: | 
					 | 
					 | 
					                for layer in rec.stock_valuation_layer_ids: | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                rec.sudo().stock_valuation_layer_ids.unlink() | 
					 | 
					 | 
					                    rec.env['stock.valuation.layer.revaluation'].create([{ | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                        'product_id': layer.product_id.id, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                        'company_id': layer.company_id.id, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                        'added_value': - layer.value | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                    }]).action_validate_revaluation() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                rec.write({'state': 'draft'}) | 
					 | 
					 | 
					                rec.write({'state': 'draft'}) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    def action_landed_cost_cancel_and_delete(self): | 
					 | 
					 | 
					    def action_landed_cost_cancel_and_delete(self): | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -157,21 +186,39 @@ class StockLandedCost(models.Model): | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                product = line.move_id.product_id | 
					 | 
					 | 
					                product = line.move_id.product_id | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                if product.cost_method == 'average': | 
					 | 
					 | 
					                if product.cost_method == 'average': | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    self.calculate_avco_price() | 
					 | 
					 | 
					                    self.calculate_avco_price() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					            if rec.account_move_id: | 
					 | 
					 | 
					
 | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                account_id = rec.account_move_id | 
					 | 
					 | 
					            if rec.vendor_bill_id and rec.vendor_bill_id.mapped('line_ids'): | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                account_move_ids = account_id.line_ids | 
					 | 
					 | 
					                rec.vendor_bill_id.button_draft() | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                if account_move_ids: | 
					 | 
					 | 
					                rec.vendor_bill_id.sudo().write( | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    account_id.sudo().write( | 
					 | 
					 | 
					                    {'name': 'Delete Sequence Number'}) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                        {'state': 'draft', 'name': 'Delete Sequence Number'}) | 
					 | 
					 | 
					                landed_cost_line = rec.vendor_bill_id.mapped('line_ids').filtered( | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    account_move_ids.sudo().unlink() | 
					 | 
					 | 
					                    lambda x: x.is_landed_costs_line is True) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    account_id.sudo().unlink() | 
					 | 
					 | 
					                if landed_cost_line: | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                    landed_cost_line.unlink() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                if rec.valuation_adjustment_lines: | 
					 | 
					 | 
					                if rec.valuation_adjustment_lines: | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    rec.valuation_adjustment_lines.unlink() | 
					 | 
					 | 
					                    rec.valuation_adjustment_lines.unlink() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					            if rec.stock_valuation_layer_ids: | 
					 | 
					 | 
					                for layer in rec.stock_valuation_layer_ids: | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                rec.sudo().stock_valuation_layer_ids.unlink() | 
					 | 
					 | 
					                    rec.env['stock.valuation.layer.revaluation'].create([{ | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            rec.write({'state': 'cancel'}) | 
					 | 
					 | 
					                        'product_id': layer.product_id.id, | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                        'company_id': layer.company_id.id, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                        'added_value': - layer.value | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                    }]).action_validate_revaluation() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                rec.unlink() | 
					 | 
					 | 
					                rec.unlink() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            # if rec.account_move_id: | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #     account_id = rec.account_move_id | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #     account_move_ids = account_id.line_ids | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #     if account_move_ids: | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #         account_id.sudo().write( | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #             {'state': 'draft', 'name': 'Delete Sequence Number'}) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #         account_move_ids.sudo().unlink() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #         account_id.sudo().unlink() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            # if rec.valuation_adjustment_lines: | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #     rec.valuation_adjustment_lines.unlink() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            # if rec.stock_valuation_layer_ids: | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #     rec.sudo().stock_valuation_layer_ids.unlink() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            # rec.write({'state': 'cancel'}) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            # rec.unlink() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					    def action_landed_cost_cancel_form(self): | 
					 | 
					 | 
					    def action_landed_cost_cancel_form(self): | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        """Cancels the landed cost record and deletes its associated | 
					 | 
					 | 
					        """Cancels the landed cost record and deletes its associated | 
				
			
			
		
	
	
		
		
			
				
					| 
						
						
						
							
								
							
						
					 | 
					@ -196,18 +243,38 @@ class StockLandedCost(models.Model): | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                if product.cost_method == 'average': | 
					 | 
					 | 
					                if product.cost_method == 'average': | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                    self.calculate_avco_price() | 
					 | 
					 | 
					                    self.calculate_avco_price() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        if self.account_move_id: | 
					 | 
					 | 
					        if self.vendor_bill_id and self.vendor_bill_id.mapped('line_ids'): | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            account_id = self.account_move_id | 
					 | 
					 | 
					            self.vendor_bill_id.button_draft() | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            account_move_ids = account_id.line_ids | 
					 | 
					 | 
					            self.vendor_bill_id.sudo().write( | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            if account_move_ids: | 
					 | 
					 | 
					                {'name': 'Delete Sequence Number'}) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                account_id.sudo().write( | 
					 | 
					 | 
					            landed_cost_line = self.vendor_bill_id.mapped('line_ids').filtered( | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                    {'state': 'draft', 'name': 'Delete Sequence Number'}) | 
					 | 
					 | 
					                lambda x: x.is_landed_costs_line is True) | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                account_move_ids.sudo().unlink() | 
					 | 
					 | 
					            if landed_cost_line : | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					                account_id.sudo().unlink() | 
					 | 
					 | 
					                landed_cost_line.unlink() | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					            if self.valuation_adjustment_lines: | 
					 | 
					 | 
					            if self.valuation_adjustment_lines: | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					                self.valuation_adjustment_lines.unlink() | 
					 | 
					 | 
					                self.valuation_adjustment_lines.unlink() | 
				
			
			
		
	
		
		
			
				
					
					 | 
					 | 
					        if self.stock_valuation_layer_ids: | 
					 | 
					 | 
					            for layer in self.stock_valuation_layer_ids: | 
				
			
			
				
				
			
		
	
		
		
			
				
					
					 | 
					 | 
					            self.sudo().stock_valuation_layer_ids.unlink() | 
					 | 
					 | 
					                self.env['stock.valuation.layer.revaluation'].create([{ | 
				
			
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                    'product_id': layer.product_id.id, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                    'company_id': layer.company_id.id, | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                    'added_value': - layer.value | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					                }]).action_validate_revaluation() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #     layer.product_id.with_context(disable_auto_svl=True).standard_price -= layer.value / layer.quantity if layer.quantity else layer.value | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            # if self.stock_valuation_layer_ids: | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					            #     self.stock_valuation_layer_ids.sudo().unlink() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        # | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        # if self.account_move_id: | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        #     account_id = self.account_move_id | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        #     account_move_ids = account_id.line_ids | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        #     if account_move_ids: | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        #         account_id.sudo().write( | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        #             {'state': 'draft', 'name': 'Delete Sequence Number'}) | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        #         account_move_ids.sudo().unlink() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        #         account_id.sudo().unlink() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        # if self.valuation_adjustment_lines: | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        #     self.valuation_adjustment_lines.unlink() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        # if self.stock_valuation_layer_ids: | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					 | 
					 | 
					 | 
					        #     self.sudo().stock_valuation_layer_ids.unlink() | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					
 | 
					 | 
					 | 
					
 | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					        landed_mode = self.env['ir.config_parameter'].sudo().get_param( | 
					 | 
					 | 
					        landed_mode = self.env['ir.config_parameter'].sudo().get_param( | 
				
			
			
		
	
		
		
			
				
					 | 
					 | 
					            'cancel_landed_cost_odoo.land_cost_cancel_modes') | 
					 | 
					 | 
					            'cancel_landed_cost_odoo.land_cost_cancel_modes') | 
				
			
			
		
	
	
		
		
			
				
					| 
						
							
								
							
						
						
						
					 | 
					
  |