changeset 4848cd14c08c in modules/account_asset:default
details: 
https://hg.tryton.org/modules/account_asset?cmd=changeset&node=4848cd14c08c
description:
        Add revisions when updating an asset

        issue9767
        review304641002
diffstat:

 CHANGELOG                        |   1 +
 __init__.py                      |   2 +-
 asset.py                         |  67 ++++++++++++++++++++++++++++++++++-----
 asset.xml                        |  16 ++++++++-
 tests/scenario_account_asset.rst |   7 ++-
 view/asset_form.xml              |   3 +
 view/asset_update_start_form.xml |   7 +++-
 view/revision_form.xml           |  13 +++++++
 view/revision_tree.xml           |  10 +++++
 9 files changed, 110 insertions(+), 16 deletions(-)

diffs (244 lines):

diff -r d8e35d801b41 -r 4848cd14c08c CHANGELOG
--- a/CHANGELOG Thu Sep 02 23:19:36 2021 +0200
+++ b/CHANGELOG Mon Oct 04 18:53:55 2021 +0200
@@ -1,3 +1,4 @@
+* Add revisions when updating an asset
 * Allow resetting running assets without moves to draft
 * Allow refreshing pending asset lines
 
diff -r d8e35d801b41 -r 4848cd14c08c __init__.py
--- a/__init__.py       Thu Sep 02 23:19:36 2021 +0200
+++ b/__init__.py       Mon Oct 04 18:53:55 2021 +0200
@@ -14,7 +14,7 @@
         asset.AssetLine,
         asset.AssetUpdateMove,
         asset.CreateMovesStart,
-        asset.UpdateAssetStart,
+        asset.AssetRevision,
         asset.UpdateAssetShowDepreciation,
         asset.PrintDepreciationTableStart,
         product.Category,
diff -r d8e35d801b41 -r 4848cd14c08c asset.py
--- a/asset.py  Thu Sep 02 23:19:36 2021 +0200
+++ b/asset.py  Mon Oct 04 18:53:55 2021 +0200
@@ -205,6 +205,8 @@
             },
         depends=['company'])
     comment = fields.Text('Comment')
+    revisions = fields.One2Many(
+        'account.asset.revision', 'asset', "Revisions", readonly=True)
 
     @classmethod
     def __setup__(cls):
@@ -795,14 +797,6 @@
         return 'end'
 
 
-class UpdateAssetStart(ModelView):
-    'Update Asset Start'
-    __name__ = 'account.asset.update.start'
-    value = fields.Numeric('Asset Value', required=True)
-    residual_value = fields.Numeric('Residual Value', required=True)
-    end_date = fields.Date('End Date', required=True)
-
-
 class UpdateAssetShowDepreciation(ModelView):
     'Update Asset Show Depreciation'
     __name__ = 'account.asset.update.show_depreciation'
@@ -827,8 +821,8 @@
 class UpdateAsset(Wizard):
     'Update Asset'
     __name__ = 'account.asset.update'
-    start = StateView('account.asset.update.start',
-        'account_asset.asset_update_start_view_form', [
+    start = StateView('account.asset.revision',
+        'account_asset.asset_revision_view_form', [
             Button('Cancel', 'end', 'tryton-cancel'),
             Button('OK', 'update_asset', 'tryton-ok', True),
             ])
@@ -846,6 +840,7 @@
             'value': self.record.value,
             'residual_value': self.record.residual_value,
             'end_date': self.record.end_date,
+            'asset': self.record.id,
             }
 
     def transition_update_asset(self):
@@ -932,9 +927,61 @@
                 })
         self.model.clear_lines([self.record])
         self.model.create_lines([self.record])
+        self.start.asset = self.record
+        self.start.save()
         return 'end'
 
 
+class AssetRevision(ModelSQL, ModelView):
+    "Asset Revision"
+    __name__ = 'account.asset.revision'
+    currency = fields.Function(
+        fields.Many2One('currency.currency', "Currency"),
+        'on_change_with_currency')
+    value = Monetary(
+        "Asset Value", currency='currency', digits='currency',
+        required=True)
+    residual_value = Monetary(
+        "Residual Value", currency='currency', digits='currency',
+        required=True)
+    end_date = fields.Date("End Date", required=True)
+    origin = fields.Reference("Origin", selection='get_origins', select=True)
+    description = fields.Char("Description")
+    asset = fields.Many2One(
+        'account.asset', "Asset", select=True, required=True)
+
+    @classmethod
+    def __setup__(cls):
+        super().__setup__()
+        cls.__access__.add('asset')
+
+    @fields.depends('asset', '_parent_asset.currency')
+    def on_change_with_currency(self, name=None):
+        if self.asset and self.asset.currency:
+            return self.asset.currency.id
+
+    @fields.depends('origin', 'value', 'asset', '_parent_asset.value')
+    def on_change_origin(self, name=None):
+        pool = Pool()
+        InvoiceLine = pool.get('account.invoice.line')
+        if isinstance(self.origin, InvoiceLine) and self.origin.id >= 0:
+            self.value = self.asset.value + self.origin.amount
+
+    @staticmethod
+    def _get_origin():
+        "Return list of Model names for origin Reference"
+        return ['account.invoice.line']
+
+    @classmethod
+    def get_origins(cls):
+        pool = Pool()
+        IrModel = pool.get('ir.model')
+
+        get_name = IrModel.get_name
+        models = cls._get_origin()
+        return [(None, '')] + [(m, get_name(m)) for m in models]
+
+
 class AssetDepreciationTable(CompanyReport):
     'Asset Depreciation Table'
     __name__ = 'account.asset.depreciation_table'
diff -r d8e35d801b41 -r 4848cd14c08c asset.xml
--- a/asset.xml Thu Sep 02 23:19:36 2021 +0200
+++ b/asset.xml Mon Oct 04 18:53:55 2021 +0200
@@ -186,8 +186,20 @@
             <field name="name">asset_create_moves_start_form</field>
         </record>
 
-        <record model="ir.ui.view" id="asset_update_start_view_form">
-            <field name="model">account.asset.update.start</field>
+        <record model="ir.ui.view" id="revision_view_form">
+            <field name="model">account.asset.revision</field>
+            <field name="type">form</field>
+            <field name="name">revision_form</field>
+        </record>
+
+        <record model="ir.ui.view" id="revision_view_tree">
+            <field name="model">account.asset.revision</field>
+            <field name="type">tree</field>
+            <field name="name">revision_tree</field>
+        </record>
+
+        <record model="ir.ui.view" id="asset_revision_view_form">
+            <field name="model">account.asset.revision</field>
             <field name="type">form</field>
             <field name="name">asset_update_start_form</field>
         </record>
diff -r d8e35d801b41 -r 4848cd14c08c tests/scenario_account_asset.rst
--- a/tests/scenario_account_asset.rst  Thu Sep 02 23:19:36 2021 +0200
+++ b/tests/scenario_account_asset.rst  Mon Oct 04 18:53:55 2021 +0200
@@ -170,7 +170,7 @@
 Update the asset::
 
     >>> update = Wizard('account.asset.update', [asset])
-    >>> update.form.value = Decimal('1100')
+    >>> update.form.value = Decimal('1100.00')
     >>> update.execute('update_asset')
     >>> update.form.amount
     Decimal('100.00')
@@ -192,7 +192,10 @@
     >>> update.execute('create_move')
     >>> asset.reload()
     >>> asset.value
-    Decimal('1100')
+    Decimal('1100.00')
+    >>> revision, = asset.revisions
+    >>> revision.value
+    Decimal('1100.00')
     >>> [l.depreciation for l in asset.lines[:3]]
     [Decimal('37.50'), Decimal('37.50'), Decimal('37.50')]
     >>> [l.depreciation for l in asset.lines[3:-1]] == [Decimal('42.26')] * 20
diff -r d8e35d801b41 -r 4848cd14c08c view/asset_form.xml
--- a/view/asset_form.xml       Thu Sep 02 23:19:36 2021 +0200
+++ b/view/asset_form.xml       Mon Oct 04 18:53:55 2021 +0200
@@ -45,6 +45,9 @@
             <separator name="comment" colspan="4"/>
             <field name="comment" colspan="4"/>
         </page>
+        <page name="revisions">
+            <field name="revisions" colspan="4"/>
+        </page>
     </notebook>
     <label name="state"/>
     <field name="state"/>
diff -r d8e35d801b41 -r 4848cd14c08c view/asset_update_start_form.xml
--- a/view/asset_update_start_form.xml  Thu Sep 02 23:19:36 2021 +0200
+++ b/view/asset_update_start_form.xml  Mon Oct 04 18:53:55 2021 +0200
@@ -1,11 +1,16 @@
 <?xml version="1.0"?>
 <!-- This file is part of Tryton.  The COPYRIGHT file at the top level of this
      repository contains the full copyright notices and license terms. -->
-<form>
+<form col="6">
     <label name="value"/>
     <field name="value"/>
     <label name="residual_value"/>
     <field name="residual_value"/>
     <label name="end_date"/>
     <field name="end_date"/>
+    <label name="origin"/>
+    <field name="origin" colspan="2"/>
+    <label name="description"/>
+    <field name="description" colspan="2"/>
+    <field name="asset" invisible="1"/>
 </form>
diff -r d8e35d801b41 -r 4848cd14c08c view/revision_form.xml
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/view/revision_form.xml    Mon Oct 04 18:53:55 2021 +0200
@@ -0,0 +1,13 @@
+<?xml version="1.0"?>
+<!-- This file is part of Tryton.  The COPYRIGHT file at the top level of
+this repository contains the full copyright notices and license terms. -->
+<form>
+  <label name="value"/>
+  <field name="value"/>
+  <label name="end_date"/>
+  <field name="end_date"/>
+  <label name="origin"/>
+  <field name="origin"/>
+  <label name="description"/>
+  <field name="description"/>
+</form>
\ No newline at end of file
diff -r d8e35d801b41 -r 4848cd14c08c view/revision_tree.xml
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/view/revision_tree.xml    Mon Oct 04 18:53:55 2021 +0200
@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+<!-- This file is part of Tryton.  The COPYRIGHT file at the top level of
+this repository contains the full copyright notices and license terms. -->
+<tree>
+    <field name="asset"/>
+    <field name="end_date"/>
+    <field name="value" expand="1"/>
+    <field name="description"/>
+    <field name="origin" expand="1"/>
+</tree>

Reply via email to