Added migrate property. Refactor
This commit is contained in:
parent
8451a3bf33
commit
3fed1b0c4d
23
party.py
23
party.py
|
@ -3,8 +3,11 @@
|
||||||
from trytond.model import ModelSQL, fields
|
from trytond.model import ModelSQL, fields
|
||||||
from trytond.pool import PoolMeta, Pool
|
from trytond.pool import PoolMeta, Pool
|
||||||
from trytond.modules.company.model import CompanyValueMixin
|
from trytond.modules.company.model import CompanyValueMixin
|
||||||
|
from trytond import backend
|
||||||
|
from trytond.tools.multivalue import migrate_property
|
||||||
|
|
||||||
__all__ = ['Party', 'PartyParty']
|
__all__ = ['Party', 'PartyParty']
|
||||||
|
parties_names = ['customer_to_invoice', 'supplier_to_invoice']
|
||||||
|
|
||||||
|
|
||||||
class Party:
|
class Party:
|
||||||
|
@ -19,7 +22,7 @@ class Party:
|
||||||
@classmethod
|
@classmethod
|
||||||
def multivalue_model(cls, field):
|
def multivalue_model(cls, field):
|
||||||
pool = Pool()
|
pool = Pool()
|
||||||
if field in {'customer_to_invoice', 'supplier_to_invoice'}:
|
if field in parties_names:
|
||||||
return pool.get('party.party.party')
|
return pool.get('party.party.party')
|
||||||
return super(Party, cls).multivalue_model(field)
|
return super(Party, cls).multivalue_model(field)
|
||||||
|
|
||||||
|
@ -29,3 +32,21 @@ class PartyParty(ModelSQL, CompanyValueMixin):
|
||||||
__name__ = 'party.party.party'
|
__name__ = 'party.party.party'
|
||||||
customer_to_invoice = fields.Many2One('party.party', 'Customer to invoice')
|
customer_to_invoice = fields.Many2One('party.party', 'Customer to invoice')
|
||||||
supplier_to_invoice = fields.Many2One('party.party', 'Supplier to invoice')
|
supplier_to_invoice = fields.Many2One('party.party', 'Supplier to invoice')
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def __register__(cls, module_name):
|
||||||
|
TableHandler = backend.get('TableHandler')
|
||||||
|
exist = TableHandler.table_exist(cls._table)
|
||||||
|
|
||||||
|
super(PartyParty, cls).__register__(module_name)
|
||||||
|
|
||||||
|
if not exist:
|
||||||
|
cls._migrate_property([], [], [])
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _migrate_property(cls, field_names, value_names, fields):
|
||||||
|
field_names.extend(parties_names)
|
||||||
|
value_names.extend(parties_names)
|
||||||
|
fields.append('company')
|
||||||
|
migrate_property('party.party',
|
||||||
|
field_names, cls, value_names, fields=fields)
|
||||||
|
|
Loading…
Reference in New Issue