Allow to set when the depreciation move should be created
issue7424 review46431002
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -24,6 +24,7 @@ def register():
|
||||
invoice.InvoiceLine,
|
||||
account.Configuration,
|
||||
account.ConfigurationAssetSequence,
|
||||
account.ConfigurationAssetDate,
|
||||
account.Move,
|
||||
account.Period,
|
||||
account.Journal,
|
||||
|
||||
+56
-2
@@ -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'
|
||||
|
||||
|
||||
@@ -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))]
|
||||
|
||||
@@ -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
|
||||
**********
|
||||
|
||||
|
||||
@@ -6,6 +6,10 @@ this repository contains the full copyright notices and license terms. -->
|
||||
<separator id="asset" string="Asset" colspan="4"/>
|
||||
<label name="asset_sequence" string="Sequence"/>
|
||||
<field name="asset_sequence"/>
|
||||
<newline/>
|
||||
<separator id="asset_move" string="Asset Move" colspan="4"/>
|
||||
<label name="asset_bymonthday"/>
|
||||
<field name="asset_bymonthday"/>
|
||||
<label name="asset_bymonth"/>
|
||||
<field name="asset_bymonth"/>
|
||||
</xpath>
|
||||
</data>
|
||||
|
||||
Reference in New Issue
Block a user