From 5200bd1567092d9e200f615ebe01cb7cf7c8eea9 Mon Sep 17 00:00:00 2001 From: Aungkokolin1997 Date: Thu, 11 Jul 2024 04:21:58 +0000 Subject: [PATCH 1/4] [IMP] stock_picking_accounting_date: Get currency rate based on accounting date --- .../models/stock_move.py | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/stock_picking_accounting_date/models/stock_move.py b/stock_picking_accounting_date/models/stock_move.py index c28e0327..e6d438e2 100644 --- a/stock_picking_accounting_date/models/stock_move.py +++ b/stock_picking_accounting_date/models/stock_move.py @@ -46,3 +46,27 @@ def _prepare_account_move_vals( if self.accounting_date: am_vals.update({"date": self.accounting_date}) return am_vals + + def _get_price_unit(self): + """Set date for convert price unit multi currency.""" + self.ensure_one() + price_unit = super()._get_price_unit() + if ( + hasattr(self, "purchase_line_id") + and self.accounting_date + and not self.origin_returned_move_id + and self.purchase_line_id + and self.product_id.id == self.purchase_line_id.product_id.id + ): + line = self.purchase_line_id + order = line.order_id + price_unit = line.price_unit + if order.currency_id != order.company_id.currency_id: + price_unit = order.currency_id._convert( + price_unit, + order.company_id.currency_id, + order.company_id, + self.accounting_date, + round=False, + ) + return price_unit From d1f92346c726911014fbc0a951a0b4e5c8fcaa65 Mon Sep 17 00:00:00 2001 From: Aungkokolin1997 Date: Thu, 15 Aug 2024 10:53:51 +0000 Subject: [PATCH 2/4] upd --- .../models/__init__.py | 1 + .../models/res_currency.py | 13 +++++++++++ .../models/stock_move.py | 22 ++----------------- 3 files changed, 16 insertions(+), 20 deletions(-) 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 e6d438e2..baa96518 100644 --- a/stock_picking_accounting_date/models/stock_move.py +++ b/stock_picking_accounting_date/models/stock_move.py @@ -50,23 +50,5 @@ def _prepare_account_move_vals( def _get_price_unit(self): """Set date for convert price unit multi currency.""" self.ensure_one() - price_unit = super()._get_price_unit() - if ( - hasattr(self, "purchase_line_id") - and self.accounting_date - and not self.origin_returned_move_id - and self.purchase_line_id - and self.product_id.id == self.purchase_line_id.product_id.id - ): - line = self.purchase_line_id - order = line.order_id - price_unit = line.price_unit - if order.currency_id != order.company_id.currency_id: - price_unit = order.currency_id._convert( - price_unit, - order.company_id.currency_id, - order.company_id, - self.accounting_date, - round=False, - ) - return price_unit + self = self.with_context(accounting_date=self.accounting_date) + return super()._get_price_unit() From ed1dfc8b7993828f02b2bbc31e1a7fb990d2c040 Mon Sep 17 00:00:00 2001 From: Aungkokolin1997 Date: Fri, 16 Aug 2024 01:48:40 +0000 Subject: [PATCH 3/4] adj --- stock_picking_accounting_date/models/stock_move.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stock_picking_accounting_date/models/stock_move.py b/stock_picking_accounting_date/models/stock_move.py index baa96518..9c02c2d6 100644 --- a/stock_picking_accounting_date/models/stock_move.py +++ b/stock_picking_accounting_date/models/stock_move.py @@ -48,7 +48,8 @@ def _prepare_account_move_vals( return am_vals def _get_price_unit(self): - """Set date for convert price unit multi currency.""" + """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() From 061687f22c9be2a141c9de3ca84230bfe4c8b7f6 Mon Sep 17 00:00:00 2001 From: Aungkokolin1997 Date: Fri, 16 Aug 2024 02:06:59 +0000 Subject: [PATCH 4/4] adj --- stock_picking_accounting_date/models/stock_move.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/stock_picking_accounting_date/models/stock_move.py b/stock_picking_accounting_date/models/stock_move.py index 9c02c2d6..33f05a5c 100644 --- a/stock_picking_accounting_date/models/stock_move.py +++ b/stock_picking_accounting_date/models/stock_move.py @@ -49,7 +49,8 @@ def _prepare_account_move_vals( def _get_price_unit(self): """Passes the accounting_date to be used in currency conversion for receipts - in foreign currency purchases.""" + in foreign currency purchases. + """ self.ensure_one() self = self.with_context(accounting_date=self.accounting_date) return super()._get_price_unit()