This repository has been archived by the owner on Jan 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathproduct.py
90 lines (73 loc) · 2.87 KB
/
product.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# 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 import backend
from trytond.model import fields
from trytond.modules.account_product.product import (
account_used, template_property)
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Eval
class Category(metaclass=PoolMeta):
__name__ = 'product.category'
account_cogs = fields.MultiValue(fields.Many2One('account.account',
'Account Cost of Goods Sold', domain=[
('closed', '!=', True),
('type.expense', '=', True),
('company', '=', Eval('context', {}).get('company', -1)),
],
states={
'invisible': (~Eval('context', {}, ).get('company')
| Eval('account_parent')
| ~Eval('accounting', False)),
}))
@classmethod
def multivalue_model(cls, field):
pool = Pool()
if field == 'account_cogs':
return pool.get('product.category.account')
return super(Category, cls).multivalue_model(field)
@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
class CategoryAccount(metaclass=PoolMeta):
__name__ = 'product.category.account'
account_cogs = fields.Many2One(
'account.account', "Account Cost of Goods Sold",
domain=[
('closed', '!=', True),
('type.expense', '=', True),
('company', '=', Eval('company', -1)),
])
@classmethod
def __register__(cls, module_name):
exist = backend.TableHandler.table_exist(cls._table)
if exist:
table = cls.__table_handler__(module_name)
exist &= table.column_exist('account_cogs')
super(CategoryAccount, cls).__register__(module_name)
if not exist:
# Re-migration
cls._migrate_property([], [], [])
@classmethod
def _migrate_property(cls, field_names, value_names, fields):
field_names.append('account_cogs')
value_names.append('account_cogs')
super(CategoryAccount, cls)._migrate_property(
field_names, value_names, fields)
@classmethod
def get_account_stock_type_statements(cls):
return super().get_account_stock_type_statements() + ['balance']
class Template(metaclass=PoolMeta):
__name__ = 'product.template'
@property
@account_used('account_cogs', 'account_category')
def account_cogs_used(self):
pass
class Product(metaclass=PoolMeta):
__name__ = 'product.product'
account_cogs_used = template_property('account_cogs_used')