trytond-account_invoice_par.../party.py

66 lines
2.3 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
2018-07-12 11:43:01 +02:00
from trytond.tools.multivalue import migrate_property
2018-09-25 22:36:52 +02:00
from trytond.modules.company.model import CompanyValueMixin
__all__ = ['Party', 'PartyInvoiceTo']
2015-12-31 14:46:14 +01:00
2018-07-12 11:43:01 +02:00
parties_names = ['customer_to_invoice', 'supplier_to_invoice']
2015-12-31 14:46:14 +01:00
2019-02-28 13:56:36 +01:00
class Party(metaclass=PoolMeta):
2015-12-31 14:46:14 +01:00
__name__ = 'party.party'
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-09-25 22:36:52 +02:00
invoice_to_parties = fields.One2Many('party.party.invoice_to',
'party', 'Invoice to parties')
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-09-25 22:36:52 +02:00
return pool.get('party.party.invoice_to')
2018-07-11 17:02:44 +02:00
return super(Party, cls).multivalue_model(field)
def multivalue_record(self, field, **pattern):
Value = self.multivalue_model(field)
if Value.__name__ == 'party.party.invoice_to':
pattern = pattern.copy()
pattern['party'] = self
return Value(**pattern)
return super(Party, self).multivalue_record(field, **pattern)
2018-07-11 17:02:44 +02:00
2018-09-25 22:36:52 +02:00
class PartyInvoiceTo(ModelSQL, CompanyValueMixin):
"Party Invoice to"
__name__ = 'party.party.invoice_to'
party = fields.Many2One('party.party', 'Party', ondelete='CASCADE',
select=True)
2018-07-11 17:02:44 +02:00
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):
table = cls.__table_handler__(module_name)
exist = table.table_exist(cls._table)
2018-07-12 11:43:01 +02:00
2018-09-25 22:36:52 +02:00
super(PartyInvoiceTo, cls).__register__(module_name)
2018-07-12 11:43:01 +02:00
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',
2018-09-25 22:36:52 +02:00
field_names, cls, value_names, parent='party', fields=fields)