This repository has been archived by the owner on Jan 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
account.py
137 lines (120 loc) · 5.08 KB
/
account.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# 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 sql import Literal, Null
from sql.aggregate import Min, Sum
from sql.functions import CurrentTimestamp
from trytond.model import ModelSQL, ModelView, fields
from trytond.modules.currency.fields import Monetary
from trytond.pool import Pool, PoolMeta
from trytond.pyson import Bool, Eval
from trytond.transaction import Transaction
class TaxTemplate(metaclass=PoolMeta):
__name__ = 'account.tax.template'
ec_sales_list_code = fields.Char("EC Sales List Code")
def _get_tax_value(self, tax=None):
value = super(TaxTemplate, self)._get_tax_value(tax=tax)
if not tax or tax.ec_sales_list_code != self.ec_sales_list_code:
value['ec_sales_list_code'] = self.ec_sales_list_code
return value
class Tax(metaclass=PoolMeta):
__name__ = 'account.tax'
ec_sales_list_code = fields.Char("EC Sales List Code",
states={
'readonly': (Bool(Eval('template', -1))
& ~Eval('template_override', False)),
})
class ECSalesList(ModelSQL, ModelView):
"EC Sales List"
__name__ = 'account.ec_sales_list'
company_tax_identifier = fields.Many2One(
'party.identifier', "Company Tax Identifier")
party = fields.Many2One('party.party', "Party")
party_tax_identifier = fields.Many2One(
'party.identifier', "Party Tax Identifier")
code = fields.Char("Code")
amount = Monetary(
"Amount", currency='currency', digits='currency')
currency = fields.Many2One('currency.currency', "Currency")
@classmethod
def table_query(cls):
pool = Pool()
Company = pool.get('company.company')
Invoice = pool.get('account.invoice')
Move = pool.get('account.move')
Line = pool.get('account.move.line')
TaxLine = pool.get('account.tax.line')
Period = pool.get('account.period')
Tax = pool.get('account.tax')
context = Transaction().context
company = Company.__table__()
invoice = Invoice.__table__()
move = Move.__table__()
line = Line.__table__()
tax_line = TaxLine.__table__()
period = Period.__table__()
tax = Tax.__table__()
where = invoice.company == context.get('company')
if context.get('fiscalyear'):
where &= (period.fiscalyear == context.get('fiscalyear'))
if context.get('period'):
where &= (period.id == context.get('period'))
if context.get('start_date'):
where &= (move.date >= context.get('start_date'))
if context.get('end_date'):
where &= (move.date <= context.get('end_date'))
where &= ((tax.ec_sales_list_code != Null)
& (tax.ec_sales_list_code != ''))
where &= tax_line.type == 'base'
where &= invoice.type == 'out'
return (tax_line
.join(tax, condition=tax_line.tax == tax.id)
.join(line, condition=tax_line.move_line == line.id)
.join(move, condition=line.move == move.id)
.join(period, condition=move.period == period.id)
.join(invoice, condition=invoice.move == move.id)
.join(company, condition=company.id == invoice.company)
.select(
Min(tax_line.id).as_('id'),
Literal(0).as_('create_uid'),
CurrentTimestamp().as_('create_date'),
cls.write_uid.sql_cast(Literal(Null)).as_('write_uid'),
cls.write_date.sql_cast(Literal(Null)).as_('write_date'),
invoice.tax_identifier.as_('company_tax_identifier'),
invoice.party.as_('party'),
invoice.party_tax_identifier.as_('party_tax_identifier'),
tax.ec_sales_list_code.as_('code'),
Sum(tax_line.amount).as_('amount'),
company.currency.as_('currency'),
where=where,
group_by=[
invoice.tax_identifier,
invoice.party,
invoice.party_tax_identifier,
tax.ec_sales_list_code,
company.currency,
]))
class ECSalesListContext(ModelView):
"EC Sales List Context"
__name__ = 'account.ec_sales_list.context'
company = fields.Many2One('company.company', "Company", required=True)
fiscalyear = fields.Many2One(
'account.fiscalyear', "Fiscal Year", required=True,
domain=[
('company', '=', Eval('company')),
])
period = fields.Many2One(
'account.period', "Period",
domain=[
('fiscalyear', '=', Eval('fiscalyear')),
])
@classmethod
def default_company(cls):
return Transaction().context.get('company')
@classmethod
def default_fiscalyear(cls):
pool = Pool()
FiscalYear = pool.get('account.fiscalyear')
context = Transaction().context
return context.get(
'fiscalyear',
FiscalYear.find(context.get('company'), exception=False))