diff --git a/product_replenishment_cost_currency_update/__init__.py b/product_replenishment_cost_currency_update/__init__.py new file mode 100644 index 000000000..0650744f6 --- /dev/null +++ b/product_replenishment_cost_currency_update/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/product_replenishment_cost_currency_update/__manifest__.py b/product_replenishment_cost_currency_update/__manifest__.py new file mode 100644 index 000000000..f579db165 --- /dev/null +++ b/product_replenishment_cost_currency_update/__manifest__.py @@ -0,0 +1,16 @@ +{ + "name": "Replenishment Cost Currency Update", + "version": "16.0.1.0.0", + "author": "ADHOC SA", + "license": "AGPL-3", + "category": "Products", + "depends": [ + "product_replenishment_cost", + "product_planned_price", + "l10n_ar_currency_update", + ], + "data": [], + 'installable': True, + 'auto_install': False, + 'application': False, +} diff --git a/product_replenishment_cost_currency_update/models/__init__.py b/product_replenishment_cost_currency_update/models/__init__.py new file mode 100644 index 000000000..aff44f335 --- /dev/null +++ b/product_replenishment_cost_currency_update/models/__init__.py @@ -0,0 +1 @@ +from . import res_company diff --git a/product_replenishment_cost_currency_update/models/res_company.py b/product_replenishment_cost_currency_update/models/res_company.py new file mode 100644 index 000000000..d5d324197 --- /dev/null +++ b/product_replenishment_cost_currency_update/models/res_company.py @@ -0,0 +1,31 @@ +from odoo import api, models +from odoo.fields import Datetime +from datetime import timedelta + + +class ResCompany(models.Model): + + _inherit = 'res.company' + + + @api.model + def update_currency_rates(self): + currency_changes = False + last_updates = {x.id: x.l10n_ar_last_currency_sync_date for x in self.search([('currency_provider', '=', 'afip'), + ('currency_interval_unit', '!=', False)])} + + super().update_currency_rates() + for company in last_updates.keys(): + company_id = self.browse(company) + if company_id.l10n_ar_last_currency_sync_date != last_updates[company]: + currency_changes = True + + if currency_changes: + self.env.ref( + "product_replenishment_cost.ir_cron_update_cost_from_replenishment_cost" + )._trigger(at=Datetime.now()) + # Este parametro lo agregamos para que sea modificable el tiempo entre crons + time_difference = self.env['ir.config_parameter'].sudo().get_param("time_between_replenishment_costs","60") + self.env.ref( + "product_planned_price.ir_cron_update_price_from_planned" + )._trigger(at=Datetime.now() + timedelta(minutes=int(time_difference)))