2014-12-02 12:54:51 +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.
|
2012-09-24 22:17:37 +02:00
|
|
|
from trytond.model import fields
|
2017-09-20 12:19:40 +02:00
|
|
|
from trytond.modules.account_product.product import (
|
|
|
|
|
account_used, template_property)
|
2021-12-11 17:58:42 +01:00
|
|
|
from trytond.pool import Pool, PoolMeta
|
|
|
|
|
from trytond.pyson import Eval
|
2014-08-29 16:15:15 +02:00
|
|
|
|
2011-01-16 22:07:50 +01:00
|
|
|
|
2018-06-26 19:11:44 +02:00
|
|
|
class Category(metaclass=PoolMeta):
|
2012-09-24 22:17:37 +02:00
|
|
|
__name__ = 'product.category'
|
2017-04-01 00:29:49 +02:00
|
|
|
account_cogs = fields.MultiValue(fields.Many2One('account.account',
|
2011-08-04 16:57:19 +02:00
|
|
|
'Account Cost of Goods Sold', domain=[
|
2019-12-28 17:48:50 +01:00
|
|
|
('closed', '!=', True),
|
2019-03-24 18:00:01 +01:00
|
|
|
('type.expense', '=', True),
|
2013-10-09 18:25:14 +02:00
|
|
|
('company', '=', Eval('context', {}).get('company', -1)),
|
2011-08-04 16:57:19 +02:00
|
|
|
],
|
|
|
|
|
states={
|
2012-03-12 22:42:38 +01:00
|
|
|
'invisible': (~Eval('context', {}, ).get('company')
|
2016-03-19 09:04:35 +01:00
|
|
|
| Eval('account_parent')
|
|
|
|
|
| ~Eval('accounting', False)),
|
2022-04-08 19:07:12 +02:00
|
|
|
}))
|
2011-01-16 22:07:50 +01:00
|
|
|
|
2017-04-01 00:29:49 +02:00
|
|
|
@classmethod
|
|
|
|
|
def multivalue_model(cls, field):
|
|
|
|
|
pool = Pool()
|
|
|
|
|
if field == 'account_cogs':
|
|
|
|
|
return pool.get('product.category.account')
|
2025-04-04 00:45:18 +02:00
|
|
|
return super().multivalue_model(field)
|
2017-04-01 00:29:49 +02:00
|
|
|
|
2017-09-20 12:19:40 +02:00
|
|
|
@property
|
|
|
|
|
@account_used('account_cogs')
|
|
|
|
|
def account_cogs_used(self):
|
|
|
|
|
pass
|
|
|
|
|
|
2021-04-01 00:07:44 +02:00
|
|
|
@fields.depends('accounting', 'account_cogs')
|
|
|
|
|
def on_change_accounting(self):
|
|
|
|
|
super().on_change_accounting()
|
|
|
|
|
if not self.accounting:
|
|
|
|
|
self.account_cogs = None
|
|
|
|
|
|
2017-04-01 00:29:49 +02:00
|
|
|
|
2018-06-26 19:11:44 +02:00
|
|
|
class CategoryAccount(metaclass=PoolMeta):
|
2017-04-01 00:29:49 +02:00
|
|
|
__name__ = 'product.category.account'
|
|
|
|
|
account_cogs = fields.Many2One(
|
|
|
|
|
'account.account', "Account Cost of Goods Sold",
|
|
|
|
|
domain=[
|
2019-12-28 17:48:50 +01:00
|
|
|
('closed', '!=', True),
|
2019-03-24 18:00:01 +01:00
|
|
|
('type.expense', '=', True),
|
2017-04-01 00:29:49 +02:00
|
|
|
('company', '=', Eval('company', -1)),
|
2022-04-08 19:07:12 +02:00
|
|
|
])
|
2017-04-01 00:29:49 +02:00
|
|
|
|
2021-12-10 22:35:57 +01:00
|
|
|
@classmethod
|
|
|
|
|
def get_account_stock_type_statements(cls):
|
|
|
|
|
return super().get_account_stock_type_statements() + ['balance']
|
|
|
|
|
|
2011-01-16 22:07:50 +01:00
|
|
|
|
2018-06-26 19:11:44 +02:00
|
|
|
class Template(metaclass=PoolMeta):
|
2012-09-24 22:17:37 +02:00
|
|
|
__name__ = 'product.template'
|
2017-04-01 00:29:49 +02:00
|
|
|
|
2017-09-20 12:19:40 +02:00
|
|
|
@property
|
2018-06-20 12:09:43 +02:00
|
|
|
@account_used('account_cogs', 'account_category')
|
2017-09-20 12:19:40 +02:00
|
|
|
def account_cogs_used(self):
|
|
|
|
|
pass
|
|
|
|
|
|
2017-04-01 00:29:49 +02:00
|
|
|
|
2018-06-26 19:11:44 +02:00
|
|
|
class Product(metaclass=PoolMeta):
|
2016-01-02 10:24:53 +01:00
|
|
|
__name__ = 'product.product'
|
2017-09-20 12:19:40 +02:00
|
|
|
account_cogs_used = template_property('account_cogs_used')
|