Skip to content

Commit

Permalink
[4710][IMP] stock_picking_accounting_date: Get currency rate based on…
Browse files Browse the repository at this point in the history
… accounting date (#148)

* [IMP] stock_picking_accounting_date: Get currency rate based on accounting date
  • Loading branch information
AungKoKoLin1997 authored Aug 30, 2024
1 parent 4085c38 commit 8456ace
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions stock_picking_accounting_date/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from . import res_currency
from . import stock_picking
from . import stock_move
13 changes: 13 additions & 0 deletions stock_picking_accounting_date/models/res_currency.py
Original file line number Diff line number Diff line change
@@ -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)
8 changes: 8 additions & 0 deletions stock_picking_accounting_date/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

0 comments on commit 8456ace

Please sign in to comment.