Guest User

Tryton Product Supplier Price Validity Period

a guest
Jul 5th, 2016
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.69 KB | None | 0 0
  1. # This file is part of Tryton.  The COPYRIGHT file at the top level of
  2. # this repository contains the full copyright notices and license terms.
  3. import datetime
  4.  
  5. from trytond.model import ModelView, ModelSQL, MatchMixin, fields
  6. from trytond.pyson import Eval, If
  7. from trytond.transaction import Transaction
  8.  
  9. __all__ = ['ProductSupplierPrice']
  10.  
  11.  
  12. class ProductSupplierPrice(ModelSQL, ModelView, MatchMixin):
  13.     'Product Supplier Price'
  14.     __name__ = 'purchase.product_supplier.price'
  15.     start_date = fields.Date('Start Date',
  16.         domain=['OR',
  17.             ('start_date', '<=', If(~Eval('end_date', None),
  18.                     datetime.date.max,
  19.                     Eval('end_date', datetime.date.max))),
  20.             ('start_date', '=', None),
  21.         ],
  22.         depends=['end_date'])
  23.     end_date = fields.Date('End Date',
  24.         domain=['OR',
  25.             ('end_date', '>=', If(~Eval('start_date', None),
  26.                     datetime.date.min,
  27.                     Eval('start_date', datetime.date.min))),
  28.             ('end_date', '=', None),
  29.         ],
  30.         depends=['start_date'])
  31.  
  32.     @staticmethod
  33.     def get_pattern():
  34.         context = Transaction().context
  35.         return {'purchase_date': context.get('purchase_date'),}
  36.  
  37.     def match(self, quantity, uom, pattern):
  38.         if 'purchase_date' in pattern:
  39.             pattern = pattern.copy()
  40.             purchase_date = pattern.pop('purchase_date')
  41.             start = self.start_date or datetime.date.min
  42.             end = self.end_date or datetime.date.max
  43.             if not (start <= purchase_date <= end):
  44.                 return False
  45.         return super(ProductSupplierPrice, self).match(quantity, uom, pattern)
Advertisement
Add Comment
Please, Sign In to add comment