Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[4710][IMP] stock_picking_accounting_date: Get currency rate based on accounting date #148

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
6 changes: 6 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,9 @@ 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."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""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()
Loading