You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
					
					
						
							45 lines
						
					
					
						
							2.1 KiB
						
					
					
				
			
		
		
		
			
			
			
		
		
	
	
							45 lines
						
					
					
						
							2.1 KiB
						
					
					
				| # -*- coding: utf-8 -*- | |
| ################################################################################ | |
| # | |
| #    Cybrosys Technologies Pvt. Ltd. | |
| # | |
| #    Copyright (C) 2024-TODAY Cybrosys Technologies(<https://www.cybrosys.com>). | |
| #    Author: Farook Al Ameen (odoo@cybrosys.info) | |
| # | |
| #    You can modify it under the terms of the GNU AFFERO | |
| #    GENERAL PUBLIC LICENSE (AGPL v3), Version 3. | |
| # | |
| #    This program is distributed in the hope that it will be useful, | |
| #    but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | |
| #    GNU AFFERO GENERAL PUBLIC LICENSE (AGPL v3) for more details. | |
| # | |
| #    You should have received a copy of the GNU AFFERO GENERAL PUBLIC LICENSE | |
| #    (AGPL v3) along with this program. | |
| #    If not, see <http://www.gnu.org/licenses/>. | |
| # | |
| ################################################################################ | |
| from odoo import api, fields, models | |
| 
 | |
| 
 | |
| class PurchaseOrder(models.Model): | |
|     """This class extends the base 'purchase.order' model to introduce a | |
|     new field, 'is_exchange',which allows users to manually apply an exchange | |
|     rate for a transaction. When this option is enabled, users can specify | |
|     the exchange rate through the 'rate' field.""" | |
|     _inherit = 'purchase.order' | |
| 
 | |
|     is_exchange = fields.Boolean(string='Apply Manual Currency', | |
|                                  help='Check this box if you want to manually' | |
|                                       'apply an exchange rate for this ' | |
|                                       'transaction.') | |
|     rate = fields.Float(string='Rate', help='specify the rate', compute='_compute_rate', readonly=False, store=True, | |
|                         default=1) | |
| 
 | |
|     @api.depends('order_line.product_id') | |
|     def _compute_rate(self): | |
|         """Changing the unit price of product by changing the rate.""" | |
|         for rec in self: | |
|             if len(rec.order_line) >= 1 and rec.is_exchange: | |
|                 rec.order_line[-1].price_unit = rec.order_line[ | |
|                                                     -1].product_id.standard_price * rec.rate
 | |
| 
 |