diff --git a/CHANGELOG b/CHANGELOG index 6c7c9a87e0..796b5fedab 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Allow to set when the depreciation move should be created * Remove support for Python 2.7 Version 4.8.0 - 2018-04-23 diff --git a/__init__.py b/__init__.py index 571a6ed8c3..95bfcb76b3 100644 --- a/__init__.py +++ b/__init__.py @@ -24,6 +24,7 @@ def register(): invoice.InvoiceLine, account.Configuration, account.ConfigurationAssetSequence, + account.ConfigurationAssetDate, account.Move, account.Period, account.Journal, diff --git a/account.py b/account.py index 837fcea5fc..a6122986fa 100644 --- a/account.py +++ b/account.py @@ -7,8 +7,29 @@ from trytond.pool import PoolMeta, Pool from trytond.tools.multivalue import migrate_property from trytond.modules.company.model import CompanyValueMixin -__all__ = ['Configuration', 'ConfigurationAssetSequence', 'Move', 'Period', - 'Journal'] +__all__ = ['Configuration', 'ConfigurationAssetSequence', + 'ConfigurationAssetDate', 'Move', 'Period', 'Journal'] + +asset_bymonthday = fields.Selection([ + ('1', "First"), + ('-1', "Last"), + ], "Day of the Month", + help="The day of the month to create the depreciation moves.") +asset_bymonth = fields.Selection([ + ('1', "January"), + ('2', "February"), + ('3', "March"), + ('4', "April"), + ('5', "May"), + ('6', "June"), + ('7', "July"), + ('8', "August"), + ('9', "September"), + ('10', "October"), + ('11', "November"), + ('12', "December"), + ], "Month", sort=False, + help="The month to create the depreciation moves.") class Configuration(metaclass=PoolMeta): @@ -20,11 +41,29 @@ class Configuration(metaclass=PoolMeta): Eval('context', {}).get('company', -1), None]), ('code', '=', 'account.asset'), ])) + asset_bymonthday = fields.MultiValue(asset_bymonthday) + asset_bymonth = fields.MultiValue(asset_bymonth) + + @classmethod + def multivalue_model(cls, field): + pool = Pool() + if field in {'asset_bymonthday', 'asset_bymonth'}: + return pool.get('account.configuration.asset_date') + return super(Configuration, cls).multivalue_model(field) @classmethod def default_asset_sequence(cls, **pattern): return cls.multivalue_model('asset_sequence').default_asset_sequence() + @classmethod + def default_asset_bymonthday(cls, **pattern): + return cls.multivalue_model( + 'asset_bymonthday').default_asset_bymonthday() + + @classmethod + def default_asset_bymonth(cls, **pattern): + return cls.multivalue_model('asset_bymonth').default_asset_bymonth() + class ConfigurationAssetSequence(ModelSQL, CompanyValueMixin): "Account Configuration Asset Sequence" @@ -66,6 +105,21 @@ class ConfigurationAssetSequence(ModelSQL, CompanyValueMixin): return None +class ConfigurationAssetDate(ModelSQL, CompanyValueMixin): + "Account Configuration Asset Date" + __name__ = 'account.configuration.asset_date' + asset_bymonthday = asset_bymonthday + asset_bymonth = asset_bymonth + + @classmethod + def default_asset_bymonthday(cls): + return "-1" + + @classmethod + def default_asset_bymonth(cls): + return "12" + + class Move(metaclass=PoolMeta): __name__ = 'account.move' diff --git a/asset.py b/asset.py index 5f8b6ae201..da1831bc0b 100644 --- a/asset.py +++ b/asset.py @@ -332,6 +332,10 @@ class Asset(Workflow, ModelSQL, ModelView): Returns all the remaining dates at which asset depreciation movement will be issued. """ + pool = Pool() + Config = pool.get('account.configuration') + config = Config(1) + start_date = max([self.start_date] + [l.date for l in self.lines]) delta = relativedelta.relativedelta(self.end_date, start_date) # dateutil >= 2.0 has replace __nonzero__ by __bool__ which doesn't @@ -340,10 +344,11 @@ class Asset(Workflow, ModelSQL, ModelView): return [self.end_date] if self.frequency == 'monthly': rule = rrule.rrule(rrule.MONTHLY, dtstart=self.start_date, - bymonthday=-1) + bymonthday=int(config.asset_bymonthday)) elif self.frequency == 'yearly': rule = rrule.rrule(rrule.YEARLY, dtstart=self.start_date, - bymonth=12, bymonthday=-1) + bymonth=int(config.asset_bymonth), + bymonthday=int(config.asset_bymonthday)) dates = [d.date() for d in rule.between(date2datetime(start_date), date2datetime(self.end_date))] diff --git a/doc/index.rst b/doc/index.rst index 78fba76645..e6ac3952ae 100644 --- a/doc/index.rst +++ b/doc/index.rst @@ -35,6 +35,9 @@ The asset can be in one of this states: A wizard "Create Assets Moves" allows to post all accounting move up to a date. +The day and the month when the move will posted are defined on the accounting +configuration. + Asset Line ********** diff --git a/view/configuration_form.xml b/view/configuration_form.xml index 179c517af2..983e2de78b 100644 --- a/view/configuration_form.xml +++ b/view/configuration_form.xml @@ -6,6 +6,10 @@ this repository contains the full copyright notices and license terms. -->