mirror of
https://github.com/NaN-tic/trytond-galatea_tutorial_product.git
synced 2023-12-13 21:20:10 +01:00
esale product by shop field
This commit is contained in:
parent
7f740abeb9
commit
1da34b8119
28
tutorial.py
28
tutorial.py
|
@ -2,7 +2,8 @@
|
|||
# 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
|
||||
from trytond.pool import PoolMeta
|
||||
from trytond.pool import Pool, PoolMeta
|
||||
from trytond.transaction import Transaction
|
||||
|
||||
__all__ = ['GalateaTutorialProductTemplate', 'GalateaTutorial']
|
||||
__metaclass__ = PoolMeta
|
||||
|
@ -22,3 +23,28 @@ class GalateaTutorial:
|
|||
__name__ = 'galatea.tutorial'
|
||||
products = fields.Many2Many('galatea.tutorial-product.template',
|
||||
'tutorial', 'template', 'Product Templates')
|
||||
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:
|
||||
if shop in template.esale_saleshops:
|
||||
templates.append(template.id)
|
||||
return templates
|
||||
|
|
Loading…
Reference in a new issue