From 8456aceff9e9cc420083581596688ab52aae01b8 Mon Sep 17 00:00:00 2001 From: "Aung Ko Ko Lin (Quartile)" <45355704+AungKoKoLin1997@users.noreply.github.com> Date: Fri, 30 Aug 2024 09:50:36 +0700 Subject: [PATCH] [4710][IMP] stock_picking_accounting_date: Get currency rate based on accounting date (#148) * [IMP] stock_picking_accounting_date: Get currency rate based on accounting date --- stock_picking_accounting_date/models/__init__.py | 1 + .../models/res_currency.py | 13 +++++++++++++ stock_picking_accounting_date/models/stock_move.py | 8 ++++++++ 3 files changed, 22 insertions(+) create mode 100644 stock_picking_accounting_date/models/res_currency.py diff --git a/stock_picking_accounting_date/models/__init__.py b/stock_picking_accounting_date/models/__init__.py index 3c71fd1b..4cd336ad 100644 --- a/stock_picking_accounting_date/models/__init__.py +++ b/stock_picking_accounting_date/models/__init__.py @@ -1,2 +1,3 @@ +from . import res_currency from . import stock_picking from . import stock_move diff --git a/stock_picking_accounting_date/models/res_currency.py b/stock_picking_accounting_date/models/res_currency.py new file mode 100644 index 00000000..feb7f01e --- /dev/null +++ b/stock_picking_accounting_date/models/res_currency.py @@ -0,0 +1,13 @@ +# Copyright 2024 Quartile (https://www.quartile.co) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). + +from odoo import models + + +class ResCurrency(models.Model): + _inherit = "res.currency" + + def _convert(self, from_amount, to_currency, company, date, round=True): + if self.env.context.get("accounting_date"): + date = self.env.context.get("accounting_date") + return super()._convert(from_amount, to_currency, company, date, round) diff --git a/stock_picking_accounting_date/models/stock_move.py b/stock_picking_accounting_date/models/stock_move.py index c28e0327..33f05a5c 100644 --- a/stock_picking_accounting_date/models/stock_move.py +++ b/stock_picking_accounting_date/models/stock_move.py @@ -46,3 +46,11 @@ def _prepare_account_move_vals( if self.accounting_date: am_vals.update({"date": self.accounting_date}) return am_vals + + def _get_price_unit(self): + """Passes the accounting_date to be used in currency conversion for receipts + in foreign currency purchases. + """ + self.ensure_one() + self = self.with_context(accounting_date=self.accounting_date) + return super()._get_price_unit()