Fix property migration

This commit is contained in:
Sergio Morillo 2018-09-25 22:36:52 +02:00
parent 7803adeb4d
commit 144a702f67
2 changed files with 17 additions and 10 deletions

View File

@ -1,11 +1,11 @@
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from trytond.pool import Pool
from .party import Party, PartyParty
from .party import Party, PartyInvoiceTo
def register():
Pool.register(
Party,
PartyParty,
PartyInvoiceTo,
module='account_invoice_party_invoice_to', type_='model')

View File

@ -2,11 +2,13 @@
# this repository contains the full copyright notices and license terms.
from trytond.model import ModelSQL, fields
from trytond.pool import PoolMeta, Pool
from trytond.modules.company.model import CompanyValueMixin
from trytond import backend
from trytond.tools.multivalue import migrate_property
from trytond.modules.company.model import CompanyValueMixin
__all__ = ['Party', 'PartyInvoiceTo']
__all__ = ['Party', 'PartyParty']
parties_names = ['customer_to_invoice', 'supplier_to_invoice']
@ -18,18 +20,23 @@ class Party:
fields.Many2One('party.party', 'Customer to invoice'))
supplier_to_invoice = fields.MultiValue(
fields.Many2One('party.party', 'Supplier to invoice'))
invoice_to_parties = fields.One2Many('party.party.invoice_to',
'party', 'Invoice to parties')
@classmethod
def multivalue_model(cls, field):
pool = Pool()
if field in parties_names:
return pool.get('party.party.party')
return pool.get('party.party.invoice_to')
return super(Party, cls).multivalue_model(field)
class PartyParty(ModelSQL, CompanyValueMixin):
"Party Party"
__name__ = 'party.party.party'
class PartyInvoiceTo(ModelSQL, CompanyValueMixin):
"Party Invoice to"
__name__ = 'party.party.invoice_to'
party = fields.Many2One('party.party', 'Party', ondelete='CASCADE',
select=True)
customer_to_invoice = fields.Many2One('party.party', 'Customer to invoice')
supplier_to_invoice = fields.Many2One('party.party', 'Supplier to invoice')
@ -38,7 +45,7 @@ class PartyParty(ModelSQL, CompanyValueMixin):
TableHandler = backend.get('TableHandler')
exist = TableHandler.table_exist(cls._table)
super(PartyParty, cls).__register__(module_name)
super(PartyInvoiceTo, cls).__register__(module_name)
if not exist:
cls._migrate_property([], [], [])
@ -49,4 +56,4 @@ class PartyParty(ModelSQL, CompanyValueMixin):
value_names.extend(parties_names)
fields.append('company')
migrate_property('party.party',
field_names, cls, value_names, fields=fields)
field_names, cls, value_names, parent='party', fields=fields)