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

Conversation

AungKoKoLin1997
Copy link
Contributor

Copy link
Member

@yostashiro yostashiro left a comment

Choose a reason for hiding this comment

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

Please add a test case as well.

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
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need this condition?

Comment on lines 50 to 72
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
Copy link
Member

Choose a reason for hiding this comment

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

As we just talked, let's do something like this, and extend _convert() of the currency to use the date from the context if available.

Suggested change
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
def _get_price_unit(self):
self.ensure_one()
if self.accounting_date:
self = self.with_context(accounting_date=self.accounting_date)
return super()._get_price_unit()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe we don't need to add if self.accounting_date: because accounting_date will always have value.

@AungKoKoLin1997
Copy link
Contributor Author

Please add a test case as well.

I didn't add the tests case at the moment because I have no idea how to test conversion without currency_id in stock.

Copy link
Member

@yostashiro yostashiro left a comment

Choose a reason for hiding this comment

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

Code review.

@AungKoKoLin1997 Please do the same in the OCA and for THC and FAL.

@kanda999 Please test and make sure it works, and take care of the rest in the coming week.

@@ -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."""


def _get_price_unit(self):
"""Passes the accounting_date to be used in currency conversion for receipts
in foreign currency purchases."""
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
in foreign currency purchases."""
in foreign currency purchases.
"""

https://peps.python.org/pep-0257/

Unless the entire docstring fits on a line, place the closing quotes on a line by themselves. This way, Emacs’ fill-paragraph command can be used on it.

@AungKoKoLin1997
Copy link
Contributor Author

@yostashiro I just noticed we don't have the adjustment that we did in thc-oca for axls-oca repo.
Should we handle in separate PR?
https://github.com/qrtl/thc-oca/blob/c9792fe2c3027ad7157c28b0d13a325965de96bd/stock_picking_accounting_date/models/stock_move.py#L17-L22

@yostashiro
Copy link
Member

@yostashiro I just noticed we don't have the adjustment that we did in thc-oca for axls-oca repo. Should we handle in separate PR? https://github.com/qrtl/thc-oca/blob/c9792fe2c3027ad7157c28b0d13a325965de96bd/stock_picking_accounting_date/models/stock_move.py#L17-L22

Thanks for noticing that. Let's do those in the same PRs with different commits.

@AungKoKoLin1997 AungKoKoLin1997 force-pushed the 16.0-imp-stock_picking_accounting_date branch from f7a10d8 to 061687f Compare August 16, 2024 02:49
@AungKoKoLin1997
Copy link
Contributor Author

@yostashiro I overlooked this part.

# i.e. Inventory adjustments with accounting date
if self._context.get("force_period_date"):
self.write({"accounting_date": self._context["force_period_date"]})
return am_vals

We don't need to add anything.

@kanda999 kanda999 merged commit 8456ace into 16.0 Aug 30, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants