Files
tryton/modules/commission/product.py
T

43 lines
1.3 KiB
Python
Raw Normal View History

2014-12-19 12:14:20 +01:00
# 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.model import ModelSQL, fields
2021-12-11 17:58:42 +01:00
from trytond.pool import PoolMeta
2014-12-19 12:14:20 +01:00
2018-06-26 19:11:46 +02:00
class Template(metaclass=PoolMeta):
2014-12-19 12:14:20 +01:00
__name__ = 'product.template'
principals = fields.Many2Many('product.template-commission.agent',
'template', 'agent', 'Commission Principals',
domain=[
('type_', '=', 'principal'),
2020-04-13 17:35:36 +02:00
],
help="The principals who pay a commission when the product is sold.")
2014-12-19 12:14:20 +01:00
@property
def principal(self):
company_id = self._context.get('company')
for agent in self.principals:
if agent.company.id == company_id:
return agent
2014-12-19 12:14:20 +01:00
class Template_Agent(ModelSQL):
'Product Template - Commission Agent'
__name__ = 'product.template-commission.agent'
template = fields.Many2One(
'product.template', "Template", required=True)
agent = fields.Many2One(
'commission.agent', "Agent", required=True,
2014-12-19 12:14:20 +01:00
domain=[
('type_', '=', 'principal'),
])
2018-06-26 19:11:46 +02:00
class Product(metaclass=PoolMeta):
__name__ = 'product.product'
@property
def principal(self):
return self.template.principal