Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # This file is part of Tryton. The COPYRIGHT file at the top level of
- # this repository contains the full copyright notices and license terms.
- import datetime
- from trytond.model import ModelView, ModelSQL, MatchMixin, fields
- from trytond.pyson import Eval, If
- from trytond.transaction import Transaction
- __all__ = ['ProductSupplierPrice']
- class ProductSupplierPrice(ModelSQL, ModelView, MatchMixin):
- 'Product Supplier Price'
- __name__ = 'purchase.product_supplier.price'
- start_date = fields.Date('Start Date',
- domain=['OR',
- ('start_date', '<=', If(~Eval('end_date', None),
- datetime.date.max,
- Eval('end_date', datetime.date.max))),
- ('start_date', '=', None),
- ],
- depends=['end_date'])
- end_date = fields.Date('End Date',
- domain=['OR',
- ('end_date', '>=', If(~Eval('start_date', None),
- datetime.date.min,
- Eval('start_date', datetime.date.min))),
- ('end_date', '=', None),
- ],
- depends=['start_date'])
- @staticmethod
- def get_pattern():
- context = Transaction().context
- return {'purchase_date': context.get('purchase_date'),}
- def match(self, quantity, uom, pattern):
- if 'purchase_date' in pattern:
- pattern = pattern.copy()
- purchase_date = pattern.pop('purchase_date')
- start = self.start_date or datetime.date.min
- end = self.end_date or datetime.date.max
- if not (start <= purchase_date <= end):
- return False
- return super(ProductSupplierPrice, self).match(quantity, uom, pattern)
Advertisement
Add Comment
Please, Sign In to add comment