trytond-galatea_tutorial_pr.../tutorial.py

51 lines
1.8 KiB
Python
Raw Permalink Normal View History

2015-01-28 16:12:48 +01:00
# This file is part galatea_tutorial_product module for Tryton.
# The COPYRIGHT file at the top level of this repository contains the full
# copyright notices and license terms.
from trytond.model import ModelSQL, ModelView, fields
2015-01-29 14:19:01 +01:00
from trytond.pool import Pool, PoolMeta
from trytond.transaction import Transaction
2015-01-28 16:12:48 +01:00
__all__ = ['GalateaTutorialProductTemplate', 'GalateaTutorial']
class GalateaTutorialProductTemplate(ModelSQL, ModelView):
2015-02-18 16:51:52 +01:00
'Galatea Tutorial - Product Template'
2015-01-28 16:12:48 +01:00
__name__ = 'galatea.tutorial-product.template'
_table = 'galatea_tutorial_product_template_rel'
tutorial = fields.Many2One('galatea.tutorial', 'Tutorial',
ondelete='CASCADE', select=True, required=True)
template = fields.Many2One('product.template', 'Product Template',
ondelete='CASCADE', select=True, required=True)
class GalateaTutorial:
2016-03-29 12:00:25 +02:00
__metaclass__ = PoolMeta
2015-01-28 16:12:48 +01:00
__name__ = 'galatea.tutorial'
products = fields.Many2Many('galatea.tutorial-product.template',
'tutorial', 'template', 'Product Templates')
2015-01-29 14:19:01 +01:00
esale_products_by_shop = fields.Function(fields.Many2Many(
'product.template', None, None, 'Products by Shop'),
'get_esale_products_by_shop')
def get_esale_products_by_shop(self, name):
'''Get all products by shop
(context or user shop preferences)'''
templates = [] # ids
if not self.products:
return templates
pool = Pool()
transaction = Transaction()
shop = None
if Transaction().context.get('shop'):
SaleShop = pool.get('sale.shop')
shop = SaleShop(transaction.context.get('shop'))
if not shop:
return templates
for template in self.products:
2015-04-28 21:51:24 +02:00
if shop in template.shops:
2015-01-29 14:19:01 +01:00
templates.append(template.id)
return templates