Files

44 lines
1.6 KiB
Python
Raw Permalink Normal View History

2015-02-04 22:59:37 +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.
from trytond.model import fields
2021-12-11 17:58:42 +01:00
from trytond.pool import PoolMeta
2015-02-04 22:59:37 +01:00
from trytond.pyson import Eval
2018-06-26 19:11:45 +02:00
class Purchase(metaclass=PoolMeta):
2015-02-04 22:59:37 +01:00
__name__ = 'purchase.purchase'
@classmethod
def __setup__(cls):
2025-04-04 00:45:18 +02:00
super().__setup__()
2015-02-04 22:59:37 +01:00
for field in (cls.invoice_address, cls.warehouse):
field.states['readonly'] |= (
Eval('lines', [0]) & Eval('invoice_address'))
2020-03-01 12:33:51 +01:00
class Line(metaclass=PoolMeta):
2015-02-04 22:59:37 +01:00
__name__ = 'purchase.line'
@fields.depends(
'purchase', 'warehouse', '_parent_purchase.invoice_address')
2015-02-04 22:59:37 +01:00
def _get_tax_rule_pattern(self):
2020-03-01 12:33:51 +01:00
pattern = super()._get_tax_rule_pattern()
2015-02-04 22:59:37 +01:00
2019-08-18 19:03:12 +02:00
from_country = from_subdivision = to_country = to_subdivision = None
2015-02-04 22:59:37 +01:00
if self.purchase:
if self.purchase.invoice_address:
from_country = self.purchase.invoice_address.country
2019-08-18 19:03:12 +02:00
from_subdivision = self.purchase.invoice_address.subdivision
if self.warehouse and self.warehouse.address:
to_country = self.warehouse.address.country
to_subdivision = self.warehouse.address.subdivision
2015-02-04 22:59:37 +01:00
pattern['from_country'] = from_country.id if from_country else None
2019-08-18 19:03:12 +02:00
pattern['from_subdivision'] = (
from_subdivision.id if from_subdivision else None)
2015-02-04 22:59:37 +01:00
pattern['to_country'] = to_country.id if to_country else None
2019-08-18 19:03:12 +02:00
pattern['to_subdivision'] = (
to_subdivision.id if to_subdivision else None)
2015-02-04 22:59:37 +01:00
return pattern