Remove Property fields
issue2349 review38261003
This commit is contained in:
1 parent
0ab1f05a90
commit
b3922c0fa2
3 files changed
+56
-45
No files matched your search
@@ -15,7 +15,9 @@ def register():
|
||||
CreateDunningStart,
|
||||
ProcessDunningStart,
|
||||
Party,
|
||||
PartyDunningProcedure,
|
||||
Configuration,
|
||||
ConfigurationDefaultDunningProcedure,
|
||||
MoveLine,
|
||||
module='account_dunning', type_='model')
|
||||
Pool.register(
|
||||
|
||||
+10
-40
@@ -1,54 +1,24 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.model import fields
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.model import ModelSQL, ValueMixin, fields
|
||||
|
||||
|
||||
__all__ = ['Configuration', 'MoveLine']
|
||||
__all__ = ['Configuration', 'ConfigurationDefaultDunningProcedure', 'MoveLine']
|
||||
default_dunning_procedure = fields.Many2One(
|
||||
'account.dunning.procedure', "Default Dunning Procedure")
|
||||
|
||||
|
||||
class Configuration:
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'account.configuration'
|
||||
default_dunning_procedure = fields.Function(fields.Many2One(
|
||||
'account.dunning.procedure', 'Default Dunning Procedure'),
|
||||
'get_dunning', setter='set_dunning')
|
||||
default_dunning_procedure = fields.MultiValue(default_dunning_procedure)
|
||||
|
||||
def get_dunning(self, name):
|
||||
pool = Pool()
|
||||
Property = pool.get('ir.property')
|
||||
ModelField = pool.get('ir.model.field')
|
||||
dunning_field, = ModelField.search([
|
||||
('model.model', '=', 'party.party'),
|
||||
('name', '=', name[8:]),
|
||||
], limit=1)
|
||||
properties = Property.search([
|
||||
('field', '=', dunning_field.id),
|
||||
('res', '=', None),
|
||||
], limit=1)
|
||||
if properties:
|
||||
prop, = properties
|
||||
return prop.value.id
|
||||
|
||||
@classmethod
|
||||
def set_dunning(cls, configurations, name, value):
|
||||
pool = Pool()
|
||||
Property = pool.get('ir.property')
|
||||
ModelField = pool.get('ir.model.field')
|
||||
dunning_field, = ModelField.search([
|
||||
('model.model', '=', 'party.party'),
|
||||
('name', '=', name[8:]),
|
||||
], limit=1)
|
||||
properties = Property.search([
|
||||
('field', '=', dunning_field.id),
|
||||
('res', '=', None),
|
||||
])
|
||||
Property.delete(properties)
|
||||
if value:
|
||||
Property.create([{
|
||||
'field': dunning_field.id,
|
||||
'value': 'account.dunning.procedure,%s' % value,
|
||||
}])
|
||||
class ConfigurationDefaultDunningProcedure(ModelSQL, ValueMixin):
|
||||
"Account Configuration Default Dunning Procedure"
|
||||
__name__ = 'account.configuration.default_dunning_procedure'
|
||||
default_dunning_procedure = default_dunning_procedure
|
||||
|
||||
|
||||
class MoveLine:
|
||||
|
||||
@@ -1,13 +1,52 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
from trytond.model import fields
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond import backend
|
||||
from trytond.model import ModelSQL, ValueMixin, fields
|
||||
from trytond.pool import PoolMeta, Pool
|
||||
from trytond.tools.multivalue import migrate_property
|
||||
|
||||
__all__ = ['Party']
|
||||
__all__ = ['Party', 'PartyDunningProcedure']
|
||||
dunning_procedure = fields.Many2One(
|
||||
'account.dunning.procedure', "Dunning Procedure")
|
||||
|
||||
|
||||
class Party:
|
||||
__metaclass__ = PoolMeta
|
||||
__name__ = 'party.party'
|
||||
dunning_procedure = fields.Property(
|
||||
fields.Many2One('account.dunning.procedure', 'Dunning Procedure'))
|
||||
dunning_procedure = fields.MultiValue(dunning_procedure)
|
||||
dunning_procedures = fields.One2Many(
|
||||
'party.party.dunning_procedure', 'party', "Dunning Procedures")
|
||||
|
||||
@classmethod
|
||||
def default_dunning_procedure(cls, **pattern):
|
||||
pool = Pool()
|
||||
Configuration = pool.get('account.configuration')
|
||||
config = Configuration(1)
|
||||
dunning_procedure = config.default_dunning_procedure
|
||||
return dunning_procedure.id if dunning_procedure else None
|
||||
|
||||
|
||||
class PartyDunningProcedure(ModelSQL, ValueMixin):
|
||||
"Party Dunning Procedure"
|
||||
__name__ = 'party.party.dunning_procedure'
|
||||
party = fields.Many2One(
|
||||
'party.party', "Party", ondelete='CASCADE', select=True)
|
||||
dunning_procedure = dunning_procedure
|
||||
|
||||
@classmethod
|
||||
def __register__(cls, module_name):
|
||||
TableHandler = backend.get('TableHandler')
|
||||
exist = TableHandler.table_exist(cls._table)
|
||||
|
||||
super(PartyDunningProcedure, cls).__register__(module_name)
|
||||
|
||||
if not exist:
|
||||
cls._migrate_property([], [], [])
|
||||
|
||||
@classmethod
|
||||
def _migrate_property(cls, field_names, value_names, fields):
|
||||
field_names.append('dunning_procedure')
|
||||
value_names.append('dunning_procedure')
|
||||
migrate_property(
|
||||
'party.party', field_names, cls, value_names,
|
||||
parent='party', fields=fields)
|
||||
Reference in new issue
Block a user