Files
tryton/purchase.py
T
Cédric Krier 8a8435b063 Use depends on methods
issue5191
review45481002
2018-05-31 13:25:29 +02:00

44 lines
1.4 KiB
Python

# 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.pool import PoolMeta
from trytond.model import fields
from trytond.pyson import Eval
__all__ = ['Purchase', 'PurchaseLine']
class Purchase:
__metaclass__ = PoolMeta
__name__ = 'purchase.purchase'
@classmethod
def __setup__(cls):
super(Purchase, cls).__setup__()
for field in (cls.invoice_address, cls.warehouse):
field.states['readonly'] |= (
Eval('lines', [0]) & Eval('invoice_address'))
field.depends.extend(['invoice_address'])
class PurchaseLine:
__metaclass__ = PoolMeta
__name__ = 'purchase.line'
@fields.depends('purchase', '_parent_purchase.warehouse',
'_parent_purchase.invoice_address')
def _get_tax_rule_pattern(self):
pattern = super(PurchaseLine, self)._get_tax_rule_pattern()
from_country, to_country = None, None
if self.purchase:
if self.purchase.invoice_address:
from_country = self.purchase.invoice_address.country
warehouse = self.purchase.warehouse
if warehouse and warehouse.address:
to_country = warehouse.address.country
pattern['from_country'] = from_country.id if from_country else None
pattern['to_country'] = to_country.id if to_country else None
return pattern