Files
tryton/modules/purchase/party.py
T

88 lines
3.1 KiB
Python
Raw Normal View History

2016-10-02 15:21:09 +02: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:29 +01:00
from trytond.i18n import gettext
2019-08-21 22:51:36 +02:00
from trytond.model import fields, ModelSQL
2018-03-24 00:07:53 +01:00
from trytond.pool import PoolMeta, Pool
from trytond.pyson import Eval
2019-08-21 22:51:36 +02:00
from trytond.modules.company.model import (
CompanyMultiValueMixin, CompanyValueMixin)
2016-10-02 15:21:09 +02:00
2018-12-29 14:20:29 +01:00
from trytond.modules.party.exceptions import EraseError
2019-08-21 22:51:36 +02:00
class Party(CompanyMultiValueMixin, metaclass=PoolMeta):
__name__ = 'party.party'
customer_code = fields.MultiValue(fields.Char('Customer Code',
help="The code the party as supplier has assigned to the company"
" as customer."))
customer_codes = fields.One2Many(
'party.party.customer_code', 'party', "Customer Codes")
2021-01-19 14:59:54 +01:00
supplier_lead_time = fields.MultiValue(fields.TimeDelta("Lead Time",
help="The time from confirming the purchase order to receiving "
"the goods from the party when used as a supplier.\n"
"Used if no lead time is set on the product supplier."))
supplier_lead_times = fields.One2Many(
'party.party.supplier_lead_time', 'party', "Lead Times")
2019-08-21 22:51:36 +02:00
@classmethod
def multivalue_model(cls, field):
pool = Pool()
if field == 'customer_code':
return pool.get('party.party.customer_code')
return super().multivalue_model(field)
class CustomerCode(ModelSQL, CompanyValueMixin):
"Party Customer Code"
__name__ = 'party.party.customer_code'
party = fields.Many2One(
'party.party', "Party", ondelete='CASCADE', select=True,
context={
'company': Eval('company', -1),
},
depends=['company'])
2019-08-21 22:51:36 +02:00
customer_code = fields.Char('Customer Code')
2016-10-02 15:21:09 +02:00
2021-01-19 14:59:54 +01:00
class SupplierLeadTime(ModelSQL, CompanyValueMixin):
"Supplier Lead Time"
__name__ = 'party.party.supplier_lead_time'
party = fields.Many2One(
'party.party', "Party", ondelete='CASCADE', select=True,
context={
'company': Eval('company', -1),
},
depends=['company'])
2021-01-19 14:59:54 +01:00
supplier_lead_time = fields.TimeDelta("Lead Time")
2018-06-26 19:11:51 +02:00
class PartyReplace(metaclass=PoolMeta):
2016-10-02 15:21:09 +02:00
__name__ = 'party.replace'
@classmethod
def fields_to_replace(cls):
return super(PartyReplace, cls).fields_to_replace() + [
('purchase.product_supplier', 'party'),
('purchase.purchase', 'party'),
2020-03-28 14:25:57 +01:00
('purchase.purchase', 'invoice_party'),
2016-10-02 15:21:09 +02:00
]
2018-03-24 00:07:53 +01:00
2018-06-26 19:11:51 +02:00
class PartyErase(metaclass=PoolMeta):
2018-03-24 00:07:53 +01:00
__name__ = 'party.erase'
def check_erase_company(self, party, company):
pool = Pool()
Purchase = pool.get('purchase.purchase')
super(PartyErase, self).check_erase_company(party, company)
purchases = Purchase.search([
('party', '=', party.id),
2019-12-14 10:47:54 +01:00
('company', '=', company.id),
('state', 'not in', ['done', 'cancelled']),
2018-03-24 00:07:53 +01:00
])
if purchases:
2018-12-29 14:20:29 +01:00
raise EraseError(
gettext('purchase.msg_erase_party_pending_purchase',
party=party.rec_name,
company=company.rec_name))