2014-12-02 12:54:39 +01:00
|
|
|
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
|
|
|
# this repository contains the full copyright notices and license terms.
|
2018-12-29 14:20:28 +01:00
|
|
|
from trytond.i18n import gettext
|
2022-10-23 18:51:25 +02:00
|
|
|
from trytond.model import ModelSQL, ValueMixin, fields
|
2021-12-11 17:58:41 +01:00
|
|
|
from trytond.modules.party.exceptions import EraseError
|
2012-09-24 22:17:32 +02:00
|
|
|
from trytond.pool import Pool, PoolMeta
|
|
|
|
|
|
2017-04-01 00:26:36 +02:00
|
|
|
customer_payment_term = fields.Many2One(
|
|
|
|
|
'account.invoice.payment_term', "Customer Payment Term")
|
|
|
|
|
supplier_payment_term = fields.Many2One(
|
|
|
|
|
'account.invoice.payment_term', "Supplier Payment Term")
|
2009-01-02 17:54:34 +01:00
|
|
|
|
|
|
|
|
|
2018-06-26 19:11:42 +02:00
|
|
|
class Address(metaclass=PoolMeta):
|
2012-09-24 22:17:32 +02:00
|
|
|
__name__ = 'party.address'
|
2009-01-02 17:54:34 +01:00
|
|
|
invoice = fields.Boolean('Invoice')
|
|
|
|
|
|
|
|
|
|
|
2018-06-26 19:11:42 +02:00
|
|
|
class ContactMechanism(metaclass=PoolMeta):
|
2018-02-19 19:15:24 +01:00
|
|
|
__name__ = 'party.contact_mechanism'
|
|
|
|
|
invoice = fields.Boolean('Invoice')
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def usages(cls, _fields=None):
|
|
|
|
|
if _fields is None:
|
|
|
|
|
_fields = []
|
|
|
|
|
_fields.append('invoice')
|
|
|
|
|
return super(ContactMechanism, cls).usages(_fields=_fields)
|
|
|
|
|
|
|
|
|
|
|
2022-04-06 14:43:27 +02:00
|
|
|
class Party(metaclass=PoolMeta):
|
2012-09-24 22:17:32 +02:00
|
|
|
__name__ = 'party.party'
|
2017-04-01 00:26:36 +02:00
|
|
|
customer_payment_term = fields.MultiValue(customer_payment_term)
|
|
|
|
|
supplier_payment_term = fields.MultiValue(supplier_payment_term)
|
|
|
|
|
payment_terms = fields.One2Many(
|
|
|
|
|
'party.party.payment_term', 'party', "Payment Terms")
|
2009-01-02 17:54:34 +01:00
|
|
|
|
2017-04-01 00:26:36 +02:00
|
|
|
@classmethod
|
|
|
|
|
def multivalue_model(cls, field):
|
|
|
|
|
pool = Pool()
|
|
|
|
|
if field in {'customer_payment_term', 'supplier_payment_term'}:
|
|
|
|
|
return pool.get('party.party.payment_term')
|
|
|
|
|
return super(Party, cls).multivalue_model(field)
|
|
|
|
|
|
2020-12-23 21:46:51 +01:00
|
|
|
@classmethod
|
|
|
|
|
def default_customer_payment_term(cls, **pattern):
|
|
|
|
|
pool = Pool()
|
|
|
|
|
Configuration = pool.get('account.configuration')
|
|
|
|
|
config = Configuration(1)
|
|
|
|
|
payment_term = config.get_multivalue(
|
|
|
|
|
'default_customer_payment_term', **pattern)
|
|
|
|
|
return payment_term.id if payment_term else None
|
|
|
|
|
|
2017-04-01 00:26:36 +02:00
|
|
|
|
|
|
|
|
class PartyPaymentTerm(ModelSQL, ValueMixin):
|
|
|
|
|
"Party Payment Term"
|
|
|
|
|
__name__ = 'party.party.payment_term'
|
|
|
|
|
party = fields.Many2One(
|
2022-10-11 00:44:49 +02:00
|
|
|
'party.party', "Party", ondelete='CASCADE')
|
2017-04-01 00:26:36 +02:00
|
|
|
customer_payment_term = customer_payment_term
|
|
|
|
|
supplier_payment_term = supplier_payment_term
|
|
|
|
|
|
2016-10-02 15:19:54 +02:00
|
|
|
|
2020-03-01 12:33:51 +01:00
|
|
|
class Replace(metaclass=PoolMeta):
|
2016-10-02 15:19:54 +02:00
|
|
|
__name__ = 'party.replace'
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def fields_to_replace(cls):
|
2020-03-01 12:33:51 +01:00
|
|
|
return super().fields_to_replace() + [
|
2016-10-02 15:19:54 +02:00
|
|
|
('account.invoice', 'party'),
|
|
|
|
|
('account.invoice.line', 'party'),
|
2022-09-11 17:46:09 +02:00
|
|
|
('account.invoice.alternative_payee', 'party'),
|
2016-10-02 15:19:54 +02:00
|
|
|
]
|
2018-03-24 00:05:23 +01:00
|
|
|
|
|
|
|
|
|
2020-03-01 12:33:51 +01:00
|
|
|
class Erase(metaclass=PoolMeta):
|
2018-03-24 00:05:23 +01:00
|
|
|
__name__ = 'party.erase'
|
|
|
|
|
|
|
|
|
|
def check_erase_company(self, party, company):
|
|
|
|
|
pool = Pool()
|
|
|
|
|
Invoice = pool.get('account.invoice')
|
2020-03-01 12:33:51 +01:00
|
|
|
super().check_erase_company(party, company)
|
2018-03-24 00:05:23 +01:00
|
|
|
|
|
|
|
|
invoices = Invoice.search([
|
2022-09-11 17:46:09 +02:00
|
|
|
['OR',
|
|
|
|
|
('party', '=', party.id),
|
|
|
|
|
('alternative_payees', '=', party.id),
|
|
|
|
|
],
|
2019-12-14 10:47:54 +01:00
|
|
|
('company', '=', company.id),
|
2020-06-06 10:23:14 +01:00
|
|
|
('state', 'not in', ['paid', 'cancelled']),
|
2018-03-24 00:05:23 +01:00
|
|
|
])
|
|
|
|
|
if invoices:
|
2018-12-29 14:20:28 +01:00
|
|
|
raise EraseError(
|
|
|
|
|
gettext('account_invoice.msg_erase_party_pending_invoice',
|
|
|
|
|
party=party.rec_name,
|
|
|
|
|
company=company.rec_name))
|