Files
tryton/modules/incoterm/purchase.py
T

68 lines
2.2 KiB
Python
Raw Normal View History

2021-03-28 15:53:33 +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.
from trytond.i18n import gettext
from trytond.model import fields
from trytond.pool import PoolMeta
from trytond.pyson import Eval
2021-12-11 17:58:42 +01:00
from .common import IncotermAvailableMixin, IncotermMixin
2021-03-28 15:53:33 +02:00
class Purchase(IncotermAvailableMixin, metaclass=PoolMeta):
__name__ = 'purchase.purchase'
@classmethod
def __setup__(cls):
super().__setup__()
cls.incoterm_location.search_context['incoterm_type'] = 'purchase'
@property
@fields.depends('party')
def _party_incoterms(self):
return self.party.purchase_incoterms if self.party else []
@property
@fields.depends(methods=['_party_incoterms'])
def _incoterm_required(self):
return bool(self._party_incoterms)
def check_for_quotation(self):
from trytond.modules.purchase.exceptions import PurchaseQuotationError
super().check_for_quotation()
if not self.incoterm and self._incoterm_required:
for line in self.lines:
if line.movable:
2021-03-28 15:53:33 +02:00
raise PurchaseQuotationError(
gettext('incoterm'
'.msg_purchase_incoterm_required_for_quotation',
purchase=self.rec_name))
class RequestQuotation(IncotermMixin, metaclass=PoolMeta):
__name__ = 'purchase.request.quotation'
@classmethod
def __setup__(cls):
super().__setup__()
cls.incoterm_location.search_context['incoterm_type'] = 'purchase'
@classmethod
def _incoterm_related_party(cls):
2022-04-10 00:18:24 +02:00
return Eval('supplier'), {'supplier'}
2021-03-28 15:53:33 +02:00
class RequestCreatePurchase(metaclass=PoolMeta):
__name__ = 'purchase.request.create_purchase'
@classmethod
def _group_purchase_key(cls, requests, request):
2021-04-20 01:04:37 +02:00
return super()._group_purchase_key(requests, request) + (
2021-03-28 15:53:33 +02:00
('incoterm',
2021-10-22 15:46:47 +02:00
request.best_quotation_line.quotation.incoterm
2021-03-28 15:53:33 +02:00
if request.best_quotation_line else None),
('incoterm_location',
2021-10-22 15:46:47 +02:00
request.best_quotation_line.quotation.incoterm_location
2021-03-28 15:53:33 +02:00
if request.best_quotation_line else None),
)