changeset ebebab8dfb7b in modules/account_asset:default
details:
https://hg.tryton.org/modules/account_asset?cmd=changeset&node=ebebab8dfb7b
description:
Include running asset fully amortized in depreciation report
We use the purchase or start date and the closing move date to filter
the
assets in the report.
The closing move date is set to the accounting date of the invoice.
issue10041
review330911002
diffstat:
asset.py | 32 ++++++++++++++++++++++----------
invoice.py | 3 ++-
2 files changed, 24 insertions(+), 11 deletions(-)
diffs (109 lines):
diff -r 31cf87b94b79 -r ebebab8dfb7b asset.py
--- a/asset.py Sun May 02 10:30:09 2021 +0200
+++ b/asset.py Sun May 02 10:54:50 2021 +0200
@@ -593,7 +593,7 @@
Line.save(lines)
Move.post(moves)
- def get_closing_move(self, account):
+ def get_closing_move(self, account, date=None):
"""
Returns closing move values.
"""
@@ -603,7 +603,8 @@
Move = pool.get('account.move')
MoveLine = pool.get('account.move.line')
- date = Date.today()
+ if date is None:
+ date = Date.today()
period_id = Period.find(self.company.id, date)
if self.supplier_invoice_line:
account_asset = self.supplier_invoice_line.account.current()
@@ -666,7 +667,7 @@
@classmethod
@ModelView.button
@Workflow.transition('closed')
- def close(cls, assets, account=None):
+ def close(cls, assets, account=None, date=None):
"""
Close the assets.
If account is provided, it will be used instead of the expense account.
@@ -676,7 +677,7 @@
cls.clear_lines(assets)
moves = []
for asset in assets:
- moves.append(asset.get_closing_move(account))
+ moves.append(asset.get_closing_move(account, date=date))
Move.save(moves)
for move, asset in zip(moves, assets):
asset.move = move
@@ -1017,7 +1018,9 @@
@cached_property
def start_fixed_value(self):
- if (self.start_date < self.asset.start_date
+ if self.asset.end_date < self.start_date:
+ return self.asset.value
+ elif (self.start_date < self.asset.start_date
or not self.asset_lines):
return 0
value = self.asset_lines[0].acquired_value
@@ -1044,7 +1047,7 @@
@cached_property
def end_fixed_value(self):
if not self.asset_lines:
- return 0
+ return self.start_fixed_value
value = self.asset_lines[-1].acquired_value
date = self.asset_lines[-1].date
for line in self.update_lines:
@@ -1055,7 +1058,10 @@
@cached_property
def start_value(self):
if not self.asset_lines:
- return self.asset.value
+ if self.asset.start_date > self.end_date:
+ return self.asset.value
+ else:
+ return 0
return (self.asset_lines[0].actual_value
+ self.asset_lines[0].depreciation)
@@ -1072,7 +1078,7 @@
@cached_property
def end_value(self):
if not self.asset_lines:
- return self.asset.value
+ return self.start_value
return self.asset_lines[-1].actual_value
@cached_property
@@ -1130,8 +1136,14 @@
Asset = pool.get('account.asset')
with Transaction().set_context(_check_access=True):
assets = Asset.search([
- ('start_date', '<', self.start.end_date),
- ('end_date', '>', self.start.start_date),
+ ['OR',
+ ('purchase_date', '<=', self.start.end_date),
+ ('start_date', '<=', self.start.end_date),
+ ],
+ ['OR',
+ ('move', '=', None),
+ ('move.date', '>=', self.start.start_date),
+ ],
('state', '!=', 'draft'),
])
if not assets:
diff -r 31cf87b94b79 -r ebebab8dfb7b invoice.py
--- a/invoice.py Sun May 02 10:30:09 2021 +0200
+++ b/invoice.py Sun May 02 10:54:50 2021 +0200
@@ -78,5 +78,6 @@
def get_move_lines(self):
Asset = Pool().get('account.asset')
if self.asset:
- Asset.close([self.asset], account=self.account)
+ date = self.invoice.accounting_date or self.invoice.invoice_date
+ Asset.close([self.asset], account=self.account, date=date)
return super(InvoiceLine, self).get_move_lines()