trytond-account_invoice_par.../party.py

53 lines
1.8 KiB
Python
Raw Normal View History

2015-12-31 14:46:14 +01:00
# The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
2018-07-11 17:02:44 +02:00
from trytond.model import ModelSQL, fields
from trytond.pool import PoolMeta, Pool
from trytond.modules.company.model import CompanyValueMixin
2018-07-12 11:43:01 +02:00
from trytond import backend
from trytond.tools.multivalue import migrate_property
2015-12-31 14:46:14 +01:00
2018-07-11 17:02:44 +02:00
__all__ = ['Party', 'PartyParty']
2018-07-12 11:43:01 +02:00
parties_names = ['customer_to_invoice', 'supplier_to_invoice']
2015-12-31 14:46:14 +01:00
class Party:
__name__ = 'party.party'
2016-08-19 18:08:06 +02:00
__metaclass__ = PoolMeta
2015-12-31 14:46:14 +01:00
2018-07-11 17:02:44 +02:00
customer_to_invoice = fields.MultiValue(
2015-12-31 14:46:14 +01:00
fields.Many2One('party.party', 'Customer to invoice'))
2018-07-11 17:02:44 +02:00
supplier_to_invoice = fields.MultiValue(
2015-12-31 14:46:14 +01:00
fields.Many2One('party.party', 'Supplier to invoice'))
2018-07-11 17:02:44 +02:00
@classmethod
def multivalue_model(cls, field):
pool = Pool()
2018-07-12 11:43:01 +02:00
if field in parties_names:
2018-07-11 17:02:44 +02:00
return pool.get('party.party.party')
return super(Party, cls).multivalue_model(field)
class PartyParty(ModelSQL, CompanyValueMixin):
"Party Party"
__name__ = 'party.party.party'
customer_to_invoice = fields.Many2One('party.party', 'Customer to invoice')
supplier_to_invoice = fields.Many2One('party.party', 'Supplier to invoice')
2018-07-12 11:43:01 +02:00
@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)