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
|
2015-10-01 22:40:08 +02:00
|
|
|
def principal(self):
|
2024-08-23 01:16:26 +02:00
|
|
|
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'
|
2022-10-11 00:44:49 +02:00
|
|
|
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'),
|
|
|
|
|
])
|
2016-01-02 10:26:12 +01:00
|
|
|
|
|
|
|
|
|
2018-06-26 19:11:46 +02:00
|
|
|
class Product(metaclass=PoolMeta):
|
2016-01-02 10:26:12 +01:00
|
|
|
__name__ = 'product.product'
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def principal(self):
|
|
|
|
|
return self.template.principal
|