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.
- from trytond.pool import Pool, PoolMeta
- from trytond.pyson import Eval
- from trytond.model import ModelView, fields, ModelSQL, ModelSingleton
- __all__ = ['Configuration', 'PrinterModel']
- class Configuration(ModelSingleton, ModelSQL, ModelView):
- 'Printer Configuration'
- __name__ = 'printer.configuration'
- toner_category = fields.Property(fields.Many2One('product.category',
- 'Toner Category', ondelete='CASCADE', required=True, select=True))
- printer_category = fields.Property(fields.Many2One('product.category',
- 'Printer Category', ondelete='CASCADE', required=True, select=True))
- class PrinterModel(ModelSQL, ModelView):
- "Printer Model"
- __name__ = 'printer.printer_model'
- printer_model = fields.Many2One('product.product', 'Printer',
- required=True,
- domain=[('categories', 'child_of', [Eval('printer_category')],'parent')])
- toners = fields.Many2Many('printer.printer_model-printer.toner',
- 'printer_model', 'toner', 'Toners')
- printer_category = fields.Function(
- fields.Many2One('product.category',
- 'Printer Category'), 'get_printer_category')
- def get_printer_category(self, name):
- pool = Pool()
- PrinterConfiguration = pool.get('printer.configuration')
- printer_configuration = PrinterConfiguration(1)
- return printer_configuration.printer_category.id
- @staticmethod
- def default_printer_category():
- pool = Pool()
- PrinterConfiguration = pool.get('printer.configuration')
- printer_configuration = PrinterConfiguration(1)
- return printer_configuration.printer_category.id
Advertisement
Add Comment
Please, Sign In to add comment