2017-06-20 13:45:43 +02:00
|
|
|
# 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, ModelSQL
|
|
|
|
|
|
|
|
__all__ = ['SaleLine']
|
|
|
|
|
|
|
|
SALE_LINE_FIELD_MAP = {
|
|
|
|
'sale_party': 'party',
|
|
|
|
'sale_state': 'state',
|
|
|
|
'sale_date': 'sale_date',
|
|
|
|
'sale_shipment_party': 'shipment_party',
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-02-07 23:16:00 +01:00
|
|
|
class SaleLine(metaclass=PoolMeta):
|
2017-06-20 13:45:43 +02:00
|
|
|
__name__ = 'sale.line'
|
|
|
|
sale_party = fields.Function(fields.Many2One('party.party', 'Sale Party'),
|
|
|
|
'get_sale_field', searcher='search_sale_field')
|
|
|
|
sale_shipment_party = fields.Function(fields.Many2One('party.party',
|
|
|
|
'Sale Shipment Party'), 'get_sale_field',
|
|
|
|
searcher='search_sale_field')
|
|
|
|
sale_date = fields.Function(fields.Date('Sale Date'), 'get_sale_field',
|
|
|
|
searcher='search_sale_field')
|
|
|
|
|
|
|
|
def get_sale_field(self, name):
|
|
|
|
name = SALE_LINE_FIELD_MAP[name]
|
2019-06-27 10:35:11 +02:00
|
|
|
if not self.sale:
|
|
|
|
return
|
2017-06-20 13:45:43 +02:00
|
|
|
value = getattr(self.sale, name)
|
|
|
|
if value and isinstance(value, ModelSQL):
|
|
|
|
value = value.id
|
|
|
|
return value
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def search_sale_field(cls, name, clause):
|
|
|
|
name = SALE_LINE_FIELD_MAP[name]
|
|
|
|
return [('sale.' + name,) + tuple(clause[1:])]
|