Files

70 lines
2.2 KiB
Python
Raw Permalink Normal View History

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
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={
'invisible': (~Eval('context', {}, ).get('company')
2016-03-19 09:04:35 +01:00
| Eval('account_parent')
| ~Eval('accounting', False)),
}))
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
@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)),
])
2017-04-01 00:29:49 +02: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):
__name__ = 'product.product'
2017-09-20 12:19:40 +02:00
account_cogs_used = template_property('account_cogs_used')