/usr/lib/python2.7/dist-packages/trytond/modules/account/tax.py is in tryton-modules-account 3.4.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 | #This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
import datetime
from decimal import Decimal
from sql.aggregate import Sum
from trytond.model import ModelView, ModelSQL, MatchMixin, fields
from trytond.wizard import Wizard, StateView, StateAction, Button
from trytond import backend
from trytond.pyson import Eval, If, Bool, PYSONEncoder
from trytond.transaction import Transaction
from trytond.pool import Pool, PoolMeta
__all__ = ['TaxGroup', 'TaxCodeTemplate', 'TaxCode',
'OpenChartTaxCodeStart', 'OpenChartTaxCode',
'TaxTemplate', 'Tax', 'TaxLine', 'TaxRuleTemplate', 'TaxRule',
'TaxRuleLineTemplate', 'TaxRuleLine',
'OpenTaxCode',
'AccountTemplateTaxTemplate', 'AccountTemplate2', 'AccountTax', 'Account2']
__metaclass__ = PoolMeta
KINDS = [
('sale', 'Sale'),
('purchase', 'Purchase'),
('both', 'Both'),
]
class TaxGroup(ModelSQL, ModelView):
'Tax Group'
__name__ = 'account.tax.group'
name = fields.Char('Name', size=None, required=True, translate=True)
code = fields.Char('Code', size=None, required=True)
kind = fields.Selection(KINDS, 'Kind', required=True)
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
super(TaxGroup, cls).__register__(module_name)
cursor = Transaction().cursor
table = TableHandler(cursor, cls, module_name)
# Migration from 1.4 drop code_uniq constraint
table.drop_constraint('code_uniq')
@staticmethod
def default_kind():
return 'both'
class TaxCodeTemplate(ModelSQL, ModelView):
'Tax Code Template'
__name__ = 'account.tax.code.template'
name = fields.Char('Name', required=True, translate=True)
code = fields.Char('Code')
parent = fields.Many2One('account.tax.code.template', 'Parent')
childs = fields.One2Many('account.tax.code.template', 'parent', 'Children')
account = fields.Many2One('account.account.template', 'Account Template',
domain=[('parent', '=', None)], required=True)
description = fields.Text('Description', translate=True)
@classmethod
def __setup__(cls):
super(TaxCodeTemplate, cls).__setup__()
cls._order.insert(0, ('code', 'ASC'))
cls._order.insert(0, ('account', 'ASC'))
@classmethod
def validate(cls, templates):
super(TaxCodeTemplate, cls).validate(templates)
cls.check_recursion(templates)
def _get_tax_code_value(self, code=None):
'''
Set values for tax code creation.
'''
res = {}
if not code or code.name != self.name:
res['name'] = self.name
if not code or code.code != self.code:
res['code'] = self.code
if not code or code.description != self.description:
res['description'] = self.description
if not code or code.template.id != self.id:
res['template'] = self.id
return res
def create_tax_code(self, company_id, template2tax_code=None,
parent_id=None):
'''
Create recursively tax codes based on template.
template2tax_code is a dictionary with tax code template id as key and
tax code id as value, used to convert template id into tax code. The
dictionary is filled with new tax codes.
Return the id of the tax code created
'''
pool = Pool()
TaxCode = pool.get('account.tax.code')
Lang = pool.get('ir.lang')
Config = pool.get('ir.configuration')
if template2tax_code is None:
template2tax_code = {}
if self.id not in template2tax_code:
vals = self._get_tax_code_value()
vals['company'] = company_id
vals['parent'] = parent_id
new_tax_code, = TaxCode.create([vals])
prev_lang = self._context.get('language') or Config.get_language()
prev_data = {}
for field_name, field in self._fields.iteritems():
if getattr(field, 'translate', False):
prev_data[field_name] = getattr(self, field_name)
for lang in Lang.get_translatable_languages():
if lang == prev_lang:
continue
with Transaction().set_context(language=lang):
template = self.__class__(self.id)
data = {}
for field_name, field in template._fields.iteritems():
if (getattr(field, 'translate', False)
and (getattr(template, field_name) !=
prev_data[field_name])):
data[field_name] = getattr(template, field_name)
if data:
TaxCode.write([new_tax_code], data)
template2tax_code[self.id] = new_tax_code.id
new_id = template2tax_code[self.id]
new_childs = []
for child in self.childs:
new_childs.append(child.create_tax_code(company_id,
template2tax_code=template2tax_code, parent_id=new_id))
return new_id
class TaxCode(ModelSQL, ModelView):
'Tax Code'
__name__ = 'account.tax.code'
name = fields.Char('Name', size=None, required=True, select=True,
translate=True)
code = fields.Char('Code', size=None, select=True)
active = fields.Boolean('Active', select=True)
company = fields.Many2One('company.company', 'Company', required=True,
select=True)
parent = fields.Many2One('account.tax.code', 'Parent', select=True,
domain=[('company', '=', Eval('company', 0))], depends=['company'])
childs = fields.One2Many('account.tax.code', 'parent', 'Children',
domain=[('company', '=', Eval('company', 0))], depends=['company'])
currency_digits = fields.Function(fields.Integer('Currency Digits'),
'on_change_with_currency_digits')
sum = fields.Function(fields.Numeric('Sum',
digits=(16, Eval('currency_digits', 2)), depends=['currency_digits']),
'get_sum')
template = fields.Many2One('account.tax.code.template', 'Template')
description = fields.Text('Description', translate=True)
@classmethod
def __setup__(cls):
super(TaxCode, cls).__setup__()
cls._order.insert(0, ('code', 'ASC'))
@classmethod
def validate(cls, codes):
super(TaxCode, cls).validate(codes)
cls.check_recursion(codes)
@staticmethod
def default_active():
return True
@staticmethod
def default_company():
return Transaction().context.get('company')
@fields.depends('company')
def on_change_with_currency_digits(self, name=None):
if self.company:
return self.company.currency.digits
return 2
@classmethod
def get_sum(cls, codes, name):
cursor = Transaction().cursor
res = {}
pool = Pool()
MoveLine = pool.get('account.move.line')
TaxLine = pool.get('account.tax.line')
code = cls.__table__()
tax_line = TaxLine.__table__()
move_line = MoveLine.__table__()
childs = cls.search([
('parent', 'child_of', [c.id for c in codes]),
])
all_codes = list(set(codes) | set(childs))
line_query, _ = MoveLine.query_get(move_line)
cursor.execute(*code.join(tax_line, condition=tax_line.code == code.id
).join(move_line, condition=tax_line.move_line == move_line.id
).select(code.id, Sum(tax_line.amount),
where=code.id.in_([c.id for c in all_codes])
& code.active & line_query,
group_by=code.id))
code_sum = {}
for code_id, sum in cursor.fetchall():
# SQLite uses float for SUM
if not isinstance(sum, Decimal):
sum = Decimal(str(sum))
code_sum[code_id] = sum
for code in codes:
res.setdefault(code.id, Decimal('0.0'))
childs = cls.search([
('parent', 'child_of', [code.id]),
])
for child in childs:
res[code.id] += code.company.currency.round(
code_sum.get(child.id, Decimal('0.0')))
res[code.id] = code.company.currency.round(res[code.id])
return res
def get_rec_name(self, name):
if self.code:
return self.code + ' - ' + self.name
else:
return self.name
@classmethod
def search_rec_name(cls, name, clause):
return ['OR',
('code',) + tuple(clause[1:]),
(cls._rec_name,) + tuple(clause[1:]),
]
@classmethod
def delete(cls, codes):
codes = cls.search([
('parent', 'child_of', [c.id for c in codes]),
])
super(TaxCode, cls).delete(codes)
def update_tax_code(self, template2tax_code=None):
'''
Update recursively tax code based on template.
template2tax_code is a dictionary with tax code template id as key and
tax code id as value, used to convert template id into tax code. The
dictionary is filled with new tax codes
'''
pool = Pool()
Lang = pool.get('ir.lang')
Config = pool.get('ir.configuration')
if template2tax_code is None:
template2tax_code = {}
if self.template:
vals = self.template._get_tax_code_value(code=self)
if vals:
self.write([self], vals)
prev_lang = self._context.get('language') or Config.get_language()
prev_data = {}
for field_name, field in self.template._fields.iteritems():
if getattr(field, 'translate', False):
prev_data[field_name] = getattr(self.template, field_name)
for lang in Lang.get_translatable_languages():
if lang == prev_lang:
continue
with Transaction().set_context(language=lang):
code = self.__class__(self.id)
data = {}
for field_name, field in code.template._fields.iteritems():
if (getattr(field, 'translate', False)
and (getattr(code.template, field_name) !=
prev_data[field_name])):
data[field_name] = getattr(code.template,
field_name)
if data:
self.write([code], data)
template2tax_code[self.template.id] = self.id
for child in self.childs:
child.update_tax_code(template2tax_code=template2tax_code)
class OpenChartTaxCodeStart(ModelView):
'Open Chart of Tax Codes'
__name__ = 'account.tax.code.open_chart.start'
method = fields.Selection([
('fiscalyear', 'By Fiscal Year'),
('periods', 'By Periods'),
], 'Method', required=True)
fiscalyear = fields.Many2One('account.fiscalyear', 'Fiscal Year',
help='Leave empty for all open fiscal year',
states={
'invisible': Eval('method') != 'fiscalyear',
}, depends=['method'])
periods = fields.Many2Many('account.period', None, None, 'Periods',
help='Leave empty for all periods of all open fiscal year',
states={
'invisible': Eval('method') != 'periods',
}, depends=['method'])
@staticmethod
def default_method():
return 'periods'
class OpenChartTaxCode(Wizard):
'Open Chart of Tax Codes'
__name__ = 'account.tax.code.open_chart'
start = StateView('account.tax.code.open_chart.start',
'account.tax_code_open_chart_start_view_form', [
Button('Cancel', 'end', 'tryton-cancel'),
Button('Open', 'open_', 'tryton-ok', default=True),
])
open_ = StateAction('account.act_tax_code_tree2')
def do_open_(self, action):
if self.start.method == 'fiscalyear':
action['pyson_context'] = PYSONEncoder().encode({
'fiscalyear': (self.start.fiscalyear.id
if self.start.fiscalyear else None),
})
if self.start.fiscalyear:
action['name'] += ' - %s' % self.start.fiscalyear.rec_name
else:
action['pyson_context'] = PYSONEncoder().encode({
'periods': [x.id for x in self.start.periods],
})
period_str = ', '.join(p.rec_name for p in self.start.periods)
if period_str:
action['name'] += ' (%s)' % period_str
return action, {}
def transition_open_(self):
return 'end'
class TaxTemplate(ModelSQL, ModelView):
'Account Tax Template'
__name__ = 'account.tax.template'
name = fields.Char('Name', required=True, translate=True)
description = fields.Char('Description', required=True, translate=True)
group = fields.Many2One('account.tax.group', 'Group')
sequence = fields.Integer('Sequence')
start_date = fields.Date('Starting Date')
end_date = fields.Date('Ending Date')
amount = fields.Numeric('Amount', digits=(16, 8),
states={
'required': Eval('type') == 'fixed',
'invisible': Eval('type') != 'fixed',
},
depends=['type'])
rate = fields.Numeric('Rate', digits=(14, 10),
states={
'required': Eval('type') == 'percentage',
'invisible': Eval('type') != 'percentage',
}, depends=['type'])
type = fields.Selection([
('percentage', 'Percentage'),
('fixed', 'Fixed'),
('none', 'None'),
], 'Type', required=True)
parent = fields.Many2One('account.tax.template', 'Parent')
childs = fields.One2Many('account.tax.template', 'parent', 'Children')
invoice_account = fields.Many2One('account.account.template',
'Invoice Account')
credit_note_account = fields.Many2One('account.account.template',
'Credit Note Account')
invoice_base_code = fields.Many2One('account.tax.code.template',
'Invoice Base Code')
invoice_base_sign = fields.Numeric('Invoice Base Sign', digits=(2, 0))
invoice_tax_code = fields.Many2One('account.tax.code.template',
'Invoice Tax Code')
invoice_tax_sign = fields.Numeric('Invoice Tax Sign', digits=(2, 0))
credit_note_base_code = fields.Many2One('account.tax.code.template',
'Credit Note Base Code')
credit_note_base_sign = fields.Numeric('Credit Note Base Sign',
digits=(2, 0))
credit_note_tax_code = fields.Many2One('account.tax.code.template',
'Credit Note Tax Code')
credit_note_tax_sign = fields.Numeric('Credit Note Tax Sign',
digits=(2, 0))
account = fields.Many2One('account.account.template', 'Account Template',
domain=[('parent', '=', None)], required=True)
@classmethod
def __setup__(cls):
super(TaxTemplate, cls).__setup__()
cls._order.insert(0, ('sequence', 'ASC'))
cls._order.insert(0, ('account', 'ASC'))
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
super(TaxTemplate, cls).__register__(module_name)
cursor = Transaction().cursor
table = TableHandler(cursor, cls, module_name)
# Migration from 1.0 group is no more required
table.not_null_action('group', action='remove')
#Migration from 2.4: drop required on sequence
table.not_null_action('sequence', action='remove')
# Migration from 2.8: rename percentage into rate
if table.column_exist('percentage'):
sql_table = cls.__table__()
cursor.execute(*sql_table.update(
columns=[sql_table.rate],
values=[sql_table.percentage / 100]))
table.drop_column('percentage')
@staticmethod
def order_sequence(tables):
table, _ = tables[None]
return [table.sequence == None, table.sequence]
@staticmethod
def default_type():
return 'percentage'
@staticmethod
def default_include_base_amount():
return False
@staticmethod
def default_invoice_base_sign():
return Decimal('1')
@staticmethod
def default_invoice_tax_sign():
return Decimal('1')
@staticmethod
def default_credit_note_base_sign():
return Decimal('1')
@staticmethod
def default_credit_note_tax_sign():
return Decimal('1')
def _get_tax_value(self, tax=None):
'''
Set values for tax creation.
'''
res = {}
for field in ('name', 'description', 'sequence', 'amount',
'rate', 'type', 'invoice_base_sign', 'invoice_tax_sign',
'credit_note_base_sign', 'credit_note_tax_sign',
'start_date', 'end_date'):
if not tax or getattr(tax, field) != getattr(self, field):
res[field] = getattr(self, field)
for field in ('group',):
if not tax or getattr(tax, field) != getattr(self, field):
value = getattr(self, field)
if value:
res[field] = getattr(self, field).id
else:
res[field] = None
if not tax or tax.template != self:
res['template'] = self.id
return res
def create_tax(self, company_id, template2tax_code, template2account,
template2tax=None, parent_id=None):
'''
Create recursively taxes based on template.
template2tax_code is a dictionary with tax code template id as key and
tax code id as value, used to convert tax code template into tax code.
template2account is a dictionary with account template id as key and
account id as value, used to convert account template into account
code.
template2tax is a dictionary with tax template id as key and tax id as
value, used to convert template id into tax. The dictionary is filled
with new taxes.
Return id of the tax created
'''
pool = Pool()
Tax = pool.get('account.tax')
Lang = pool.get('ir.lang')
Config = pool.get('ir.configuration')
if template2tax is None:
template2tax = {}
if self.id not in template2tax:
vals = self._get_tax_value()
vals['company'] = company_id
vals['parent'] = parent_id
if self.invoice_account:
vals['invoice_account'] = \
template2account[self.invoice_account.id]
else:
vals['invoice_account'] = None
if self.credit_note_account:
vals['credit_note_account'] = \
template2account[self.credit_note_account.id]
else:
vals['credit_note_account'] = None
if self.invoice_base_code:
vals['invoice_base_code'] = \
template2tax_code[self.invoice_base_code.id]
else:
vals['invoice_base_code'] = None
if self.invoice_tax_code:
vals['invoice_tax_code'] = \
template2tax_code[self.invoice_tax_code.id]
else:
vals['invoice_tax_code'] = None
if self.credit_note_base_code:
vals['credit_note_base_code'] = \
template2tax_code[self.credit_note_base_code.id]
else:
vals['credit_note_base_code'] = None
if self.credit_note_tax_code:
vals['credit_note_tax_code'] = \
template2tax_code[self.credit_note_tax_code.id]
else:
vals['credit_note_tax_code'] = None
new_tax, = Tax.create([vals])
prev_lang = self._context.get('language') or Config.get_language()
prev_data = {}
for field_name, field in self._fields.iteritems():
if getattr(field, 'translate', False):
prev_data[field_name] = getattr(self, field_name)
for lang in Lang.get_translatable_languages():
if lang == prev_lang:
continue
with Transaction().set_context(language=lang):
template = self.__class__(self.id)
data = {}
for field_name, field in template._fields.iteritems():
if (getattr(field, 'translate', False)
and (getattr(template, field_name)
!= prev_data[field_name])):
data[field_name] = getattr(template, field_name)
if data:
Tax.write([new_tax], data)
template2tax[self.id] = new_tax.id
new_id = template2tax[self.id]
new_childs = []
for child in self.childs:
new_childs.append(child.create_tax(company_id, template2tax_code,
template2account, template2tax=template2tax,
parent_id=new_id))
return new_id
class Tax(ModelSQL, ModelView):
'''
Account Tax
Type:
percentage: tax = price * rate
fixed: tax = amount
none: tax = none
'''
__name__ = 'account.tax'
name = fields.Char('Name', required=True, translate=True)
description = fields.Char('Description', required=True, translate=True,
help="The name that will be used in reports")
group = fields.Many2One('account.tax.group', 'Group',
states={
'invisible': Bool(Eval('parent')),
}, depends=['parent'])
active = fields.Boolean('Active')
sequence = fields.Integer('Sequence', help='Use to order the taxes')
start_date = fields.Date('Starting Date')
end_date = fields.Date('Ending Date')
currency_digits = fields.Function(fields.Integer('Currency Digits'),
'on_change_with_currency_digits')
amount = fields.Numeric('Amount', digits=(16, Eval('currency_digits', 2)),
states={
'required': Eval('type') == 'fixed',
'invisible': Eval('type') != 'fixed',
}, help='In company\'s currency',
depends=['type', 'currency_digits'])
rate = fields.Numeric('Rate', digits=(14, 10),
states={
'required': Eval('type') == 'percentage',
'invisible': Eval('type') != 'percentage',
}, depends=['type'])
type = fields.Selection([
('percentage', 'Percentage'),
('fixed', 'Fixed'),
('none', 'None'),
], 'Type', required=True)
parent = fields.Many2One('account.tax', 'Parent', ondelete='CASCADE')
childs = fields.One2Many('account.tax', 'parent', 'Children')
company = fields.Many2One('company.company', 'Company', required=True,
domain=[
('id', If(Eval('context', {}).contains('company'), '=', '!='),
Eval('context', {}).get('company', -1)),
], select=True)
invoice_account = fields.Many2One('account.account', 'Invoice Account',
domain=[
('company', '=', Eval('company')),
('kind', 'not in', ['view', 'receivable', 'payable']),
],
states={
'readonly': (Eval('type') == 'none') | ~Eval('company'),
'required': (Eval('type') != 'none') & Eval('company'),
},
depends=['company', 'type'])
credit_note_account = fields.Many2One('account.account',
'Credit Note Account',
domain=[
('company', '=', Eval('company')),
('kind', 'not in', ['view', 'receivable', 'payable']),
],
states={
'readonly': (Eval('type') == 'none') | ~Eval('company'),
'required': (Eval('type') != 'none') & Eval('company'),
},
depends=['company', 'type'])
invoice_base_code = fields.Many2One('account.tax.code',
'Invoice Base Code',
states={
'readonly': Eval('type') == 'none',
}, depends=['type'])
invoice_base_sign = fields.Numeric('Invoice Base Sign', digits=(2, 0),
help='Usualy 1 or -1',
states={
'required': Eval('type') != 'none',
'readonly': Eval('type') == 'none',
}, depends=['type'])
invoice_tax_code = fields.Many2One('account.tax.code',
'Invoice Tax Code',
states={
'readonly': Eval('type') == 'none',
}, depends=['type'])
invoice_tax_sign = fields.Numeric('Invoice Tax Sign', digits=(2, 0),
help='Usualy 1 or -1',
states={
'required': Eval('type') != 'none',
'readonly': Eval('type') == 'none',
}, depends=['type'])
credit_note_base_code = fields.Many2One('account.tax.code',
'Credit Note Base Code',
states={
'readonly': Eval('type') == 'none',
}, depends=['type'])
credit_note_base_sign = fields.Numeric('Credit Note Base Sign',
digits=(2, 0), help='Usualy 1 or -1',
states={
'required': Eval('type') != 'none',
'readonly': Eval('type') == 'none',
}, depends=['type'])
credit_note_tax_code = fields.Many2One('account.tax.code',
'Credit Note Tax Code',
states={
'readonly': Eval('type') == 'none',
}, depends=['type'])
credit_note_tax_sign = fields.Numeric('Credit Note Tax Sign',
digits=(2, 0), help='Usualy 1 or -1',
states={
'required': Eval('type') != 'none',
'readonly': Eval('type') == 'none',
}, depends=['type'])
template = fields.Many2One('account.tax.template', 'Template')
@classmethod
def __setup__(cls):
super(Tax, cls).__setup__()
cls._order.insert(0, ('sequence', 'ASC'))
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
super(Tax, cls).__register__(module_name)
cursor = Transaction().cursor
table = TableHandler(cursor, cls, module_name)
# Migration from 1.0 group is no more required
table.not_null_action('group', action='remove')
# Migration from 2.4: drop required on sequence
table.not_null_action('sequence', action='remove')
# Migration from 2.8: rename percentage into rate
if table.column_exist('percentage'):
sql_table = cls.__table__()
cursor.execute(*sql_table.update(
columns=[sql_table.rate],
values=[sql_table.percentage / 100]))
table.drop_column('percentage')
@staticmethod
def order_sequence(tables):
table, _ = tables[None]
return [table.sequence == None, table.sequence]
@staticmethod
def default_active():
return True
@staticmethod
def default_type():
return 'percentage'
@staticmethod
def default_include_base_amount():
return False
@staticmethod
def default_invoice_base_sign():
return Decimal('1')
@staticmethod
def default_invoice_tax_sign():
return Decimal('1')
@staticmethod
def default_credit_note_base_sign():
return Decimal('1')
@staticmethod
def default_credit_note_tax_sign():
return Decimal('1')
@staticmethod
def default_company():
return Transaction().context.get('company')
@fields.depends('company')
def on_change_with_currency_digits(self, name=None):
if self.company:
return self.company.currency.digits
return 2
def _process_tax(self, price_unit):
if self.type == 'percentage':
amount = price_unit * self.rate
return {
'base': price_unit,
'amount': amount,
'tax': self,
}
if self.type == 'fixed':
amount = self.amount
return {
'base': price_unit,
'amount': amount,
'tax': self,
}
@classmethod
def _unit_compute(cls, taxes, price_unit, date):
res = []
for tax in taxes:
start_date = tax.start_date or datetime.date.min
end_date = tax.end_date or datetime.date.max
if not (start_date <= date <= end_date):
continue
if tax.type != 'none':
res.append(tax._process_tax(price_unit))
if len(tax.childs):
res.extend(cls._unit_compute(tax.childs, price_unit, date))
return res
@classmethod
def sort_taxes(cls, taxes):
'''
Return a list of taxes sorted
'''
return sorted(taxes, key=lambda t: (t.sequence, t.id))
@classmethod
def compute(cls, taxes, price_unit, quantity, date=None):
'''
Compute taxes for price_unit and quantity at the date.
Return list of dict for each taxes and their childs with:
base
amount
tax
'''
pool = Pool()
Date = pool.get('ir.date')
if date is None:
date = Date.today()
taxes = cls.sort_taxes(taxes)
res = cls._unit_compute(taxes, price_unit, date)
quantity = Decimal(str(quantity or 0.0))
for row in res:
row['base'] *= quantity
row['amount'] *= quantity
return res
def update_tax(self, template2tax_code, template2account,
template2tax=None):
'''
Update recursively taxes based on template.
template2tax_code is a dictionary with tax code template id as key and
tax code id as value, used to convert tax code template into tax code.
template2account is a dictionary with account template id as key and
account id as value, used to convert account template into account
code.
template2tax is a dictionary with tax template id as key and tax id as
value, used to convert template id into tax. The dictionary is filled
with new taxes.
'''
pool = Pool()
Lang = pool.get('ir.lang')
Config = pool.get('ir.configuration')
if template2tax is None:
template2tax = {}
if self.template:
vals = self.template._get_tax_value(tax=self)
invoice_account_id = (self.invoice_account.id
if self.invoice_account else None)
if (self.template.invoice_account and
invoice_account_id != template2account.get(
self.template.invoice_account.id)):
vals['invoice_account'] = template2account.get(
self.template.invoice_account.id)
elif (not self.template.invoice_account
and self.invoice_account):
vals['invoice_account'] = None
credit_note_account_id = (self.credit_note_account.id
if self.credit_note_account else None)
if (self.template.credit_note_account and
credit_note_account_id != template2account.get(
self.template.credit_note_account.id)):
vals['credit_note_account'] = template2account.get(
self.template.credit_note_account.id)
elif (not self.template.credit_note_account
and self.credit_note_account):
vals['credit_note_account'] = None
invoice_base_code_id = (self.invoice_base_code.id
if self.invoice_base_code else None)
if (self.template.invoice_base_code and
invoice_base_code_id != template2tax_code.get(
self.template.invoice_base_code.id)):
vals['invoice_base_code'] = template2tax_code.get(
self.template.invoice_base_code.id)
elif (not self.template.invoice_base_code
and self.invoice_base_code):
vals['invoice_base_code'] = None
invoice_tax_code_id = (self.invoice_tax_code.id
if self.invoice_tax_code else None)
if (self.template.invoice_tax_code
and invoice_tax_code_id != template2tax_code.get(
self.template.invoice_tax_code.id)):
vals['invoice_tax_code'] = template2tax_code.get(
self.template.invoice_tax_code.id)
elif (not self.template.invoice_tax_code
and self.invoice_tax_code):
vals['invoice_tax_code'] = None
credit_note_base_code_id = (self.credit_note_base_code.id
if self.credit_note_base_code else None)
if (self.template.credit_note_base_code
and credit_note_base_code_id != template2tax_code.get(
self.template.credit_note_base_code.id)):
vals['credit_note_base_code'] = template2tax_code.get(
self.template.credit_note_base_code.id)
elif (not self.template.credit_note_base_code
and self.credit_note_base_code):
vals['credit_note_base_code'] = None
credit_note_tax_code_id = (self.credit_note_tax_code.id
if self.credit_note_tax_code else None)
if (self.template.credit_note_tax_code
and credit_note_tax_code_id != template2tax_code.get(
self.template.credit_note_tax_code.id)):
vals['credit_note_tax_code'] = template2tax_code.get(
self.template.credit_note_tax_code.id)
elif (not self.template.credit_note_tax_code
and self.credit_note_tax_code):
vals['credit_note_tax_code'] = None
if vals:
self.write([self], vals)
prev_lang = self._context.get('language') or Config.get_language()
prev_data = {}
for field_name, field in self.template._fields.iteritems():
if getattr(field, 'translate', False):
prev_data[field_name] = getattr(self.template, field_name)
for lang in Lang.get_translatable_languages():
if lang == prev_lang:
continue
with Transaction().set_context(language=lang):
tax = self.__class__(self.id)
data = {}
for field_name, field in tax.template._fields.iteritems():
if (getattr(field, 'translate', False)
and (getattr(tax.template, field_name)
!= prev_data[field_name])):
data[field_name] = getattr(tax.template,
field_name)
if data:
self.write([tax], data)
template2tax[self.template.id] = self.id
for child in self.childs:
child.update_tax(template2tax_code, template2account,
template2tax=template2tax)
class TaxLine(ModelSQL, ModelView):
'Tax Line'
__name__ = 'account.tax.line'
_rec_name = 'amount'
currency_digits = fields.Function(fields.Integer('Currency Digits'),
'on_change_with_currency_digits')
amount = fields.Numeric('Amount', digits=(16, Eval('currency_digits', 2)),
required=True, depends=['currency_digits'])
code = fields.Many2One('account.tax.code', 'Code', select=True,
required=True)
tax = fields.Many2One('account.tax', 'Tax', select=True,
ondelete='RESTRICT')
move_line = fields.Many2One('account.move.line', 'Move Line',
required=True, select=True, ondelete='CASCADE')
@fields.depends('move_line')
def on_change_with_currency_digits(self, name=None):
if self.move_line:
return self.move_line.currency_digits
return 2
@fields.depends('tax')
def on_change_tax(self):
return {
'code': None,
}
class TaxRuleTemplate(ModelSQL, ModelView):
'Tax Rule Template'
__name__ = 'account.tax.rule.template'
name = fields.Char('Name', required=True, translate=True)
kind = fields.Selection(KINDS, 'Kind', required=True)
lines = fields.One2Many('account.tax.rule.line.template', 'rule', 'Lines')
account = fields.Many2One('account.account.template', 'Account Template',
domain=[('parent', '=', None)], required=True)
@staticmethod
def default_kind():
return 'both'
def _get_tax_rule_value(self, rule=None):
'''
Set values for tax rule creation.
'''
res = {}
if not rule or rule.name != self.name:
res['name'] = self.name
if not rule or rule.kind != self.kind:
res['kind'] = self.kind
if not rule or rule.template.id != self.id:
res['template'] = self.id
return res
def create_rule(self, company_id, template2rule=None):
'''
Create tax rule based on template.
template2rule is a dictionary with tax rule template id as key and tax
rule id as value, used to convert template id into tax rule. The
dictionary is filled with new tax rules.
Return id of the tax rule created
'''
pool = Pool()
Rule = pool.get('account.tax.rule')
Lang = pool.get('ir.lang')
Config = pool.get('ir.configuration')
if template2rule is None:
template2rule = {}
if self.id not in template2rule:
vals = self._get_tax_rule_value()
vals['company'] = company_id
new_rule, = Rule.create([vals])
prev_lang = self._context.get('language') or Config.get_language()
prev_data = {}
for field_name, field in self._fields.iteritems():
if getattr(field, 'translate', False):
prev_data[field_name] = getattr(self, field_name)
for lang in Lang.get_translatable_languages():
if lang == prev_lang:
continue
with Transaction().set_context(language=lang):
template = self.__class__(self.id)
data = {}
for field_name, field in template._fields.iteritems():
if (getattr(field, 'translate', False)
and (getattr(self, field_name)
!= prev_data[field_name])):
data[field_name] = getattr(self, field_name)
if data:
Rule.write([new_rule], data)
template2rule[self.id] = new_rule.id
return template2rule[self.id]
class TaxRule(ModelSQL, ModelView):
'Tax Rule'
__name__ = 'account.tax.rule'
name = fields.Char('Name', required=True, translate=True)
kind = fields.Selection(KINDS, 'Kind', required=True)
company = fields.Many2One('company.company', 'Company', required=True,
select=True, domain=[
('id', If(Eval('context', {}).contains('company'), '=', '!='),
Eval('context', {}).get('company', -1)),
])
lines = fields.One2Many('account.tax.rule.line', 'rule', 'Lines')
template = fields.Many2One('account.tax.rule.template', 'Template')
@staticmethod
def default_kind():
return 'both'
def apply(self, tax, pattern):
'''
Apply rule on tax
pattern is a dictonary with rule line field as key and match value as
value.
Return a list of the tax id to use or None
'''
pattern = pattern.copy()
pattern['group'] = tax.group.id if tax and tax.group else None
pattern['origin_tax'] = tax.id if tax else None
for line in self.lines:
if line.match(pattern):
return line.get_taxes()
return tax and [tax.id] or None
def update_rule(self, template2rule=None):
'''
Update tax rule based on template.
template2rule is a dictionary with tax rule template id as key and tax
rule id as value, used to convert template id into tax rule. The
dictionary is filled with new tax rules.
'''
pool = Pool()
Lang = pool.get('ir.lang')
Config = pool.get('ir.configuration')
if template2rule is None:
template2rule = {}
if self.template:
vals = self.template._get_tax_rule_value(rule=self)
if vals:
self.write([self], vals)
prev_lang = self._context.get('language') or Config.get_language()
prev_data = {}
for field_name, field in self.template._fields.iteritems():
if getattr(field, 'translate', False):
prev_data[field_name] = getattr(self.template, field_name)
for lang in Lang.get_translatable_languages():
if lang == prev_lang:
continue
with Transaction().set_context(language=lang):
rule = self.__class__(self.id)
data = {}
for field_name, field in rule.template._fields.iteritems():
if (getattr(field, 'translate', False)
and (getattr(rule.template, field_name)
!= prev_data[field_name])):
data[field_name] = getattr(rule.template,
field_name)
if data:
self.write([rule], data)
template2rule[self.template.id] = self.id
class TaxRuleLineTemplate(ModelSQL, ModelView):
'Tax Rule Line Template'
__name__ = 'account.tax.rule.line.template'
rule = fields.Many2One('account.tax.rule.template', 'Rule', required=True,
ondelete='CASCADE')
group = fields.Many2One('account.tax.group', 'Tax Group',
ondelete='RESTRICT')
origin_tax = fields.Many2One('account.tax.template', 'Original Tax',
domain=[
('account', '=', Eval('_parent_rule', {}).get('account', 0)),
('group', '=', Eval('group')),
['OR',
('group', '=', None),
If(Eval('_parent_rule', {}).get('kind', 'both') == 'sale',
('group.kind', 'in', ['sale', 'both']),
If(Eval('_parent_rule', {}).get('kind', 'both') ==
'purchase',
('group.kind', 'in', ['purchase', 'both']),
('group.kind', 'in', ['sale', 'purchase', 'both']))),
],
],
help=('If the original tax template is filled, the rule will be '
'applied only for this tax template.'),
depends=['group'],
ondelete='RESTRICT')
tax = fields.Many2One('account.tax.template', 'Substitution Tax',
domain=[
('account', '=', Eval('_parent_rule', {}).get('account', 0)),
('group', '=', Eval('group')),
['OR',
('group', '=', None),
If(Eval('_parent_rule', {}).get('kind', 'both') == 'sale',
('group.kind', 'in', ['sale', 'both']),
If(Eval('_parent_rule', {}).get('kind', 'both') ==
'purchase',
('group.kind', 'in', ['purchase', 'both']),
('group.kind', 'in', ['sale', 'purchase', 'both']))),
],
],
depends=['group'],
ondelete='RESTRICT')
sequence = fields.Integer('Sequence')
@classmethod
def __setup__(cls):
super(TaxRuleLineTemplate, cls).__setup__()
cls._order.insert(0, ('rule', 'ASC'))
cls._order.insert(0, ('sequence', 'ASC'))
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
table = TableHandler(cursor, cls, module_name)
super(TaxRuleLineTemplate, cls).__register__(module_name)
# Migration from 2.4: drop required on sequence
table.not_null_action('sequence', action='remove')
@staticmethod
def order_sequence(tables):
table, _ = tables[None]
return [table.sequence == None, table.sequence]
def _get_tax_rule_line_value(self, rule_line=None):
'''
Set values for tax rule line creation.
'''
res = {}
if not rule_line or rule_line.group != self.group:
res['group'] = self.group.id if self.group else None
if not rule_line or rule_line.sequence != self.sequence:
res['sequence'] = self.sequence
if not rule_line or rule_line.template != self:
res['template'] = self.id
return res
def create_rule_line(self, template2tax, template2rule,
template2rule_line=None):
'''
Create tax rule line based on template.
template2tax is a dictionary with tax template id as key and tax id as
value, used to convert template id into tax.
template2rule is a dictionary with tax rule template id as key and tax
rule id as value, used to convert template id into tax rule.
template2rule_line is a dictionary with tax rule line template id as
key and tax rule line id as value, used to convert template id into tax
rule line. The dictionary is filled with new tax rule lines.
Return id of the tax rule line created
'''
RuleLine = Pool().get('account.tax.rule.line')
if template2rule_line is None:
template2rule_line = {}
if self.id not in template2rule_line:
vals = self._get_tax_rule_line_value()
vals['rule'] = template2rule[self.rule.id]
if self.origin_tax:
vals['origin_tax'] = template2tax[self.origin_tax.id]
else:
vals['origin_tax'] = None
if self.tax:
vals['tax'] = template2tax[self.tax.id]
else:
vals['tax'] = None
new_rule_line, = RuleLine.create([vals])
template2rule_line[self.id] = new_rule_line.id
return template2rule_line[self.id]
class TaxRuleLine(ModelSQL, ModelView, MatchMixin):
'Tax Rule Line'
__name__ = 'account.tax.rule.line'
_rec_name = 'tax'
rule = fields.Many2One('account.tax.rule', 'Rule', required=True,
select=True, ondelete='CASCADE')
group = fields.Many2One('account.tax.group', 'Tax Group',
ondelete='RESTRICT')
origin_tax = fields.Many2One('account.tax', 'Original Tax',
domain=[
('company', '=', Eval('_parent_rule', {}).get('company')),
('group', '=', Eval('group')),
['OR',
('group', '=', None),
If(Eval('_parent_rule', {}).get('kind', 'both') == 'sale',
('group.kind', 'in', ['sale', 'both']),
If(Eval('_parent_rule', {}).get('kind', 'both') ==
'purchase',
('group.kind', 'in', ['purchase', 'both']),
('group.kind', 'in', ['sale', 'purchase', 'both']))),
],
],
help=('If the original tax is filled, the rule will be applied '
'only for this tax.'),
depends=['group'],
ondelete='RESTRICT')
tax = fields.Many2One('account.tax', 'Substitution Tax',
domain=[
('company', '=', Eval('_parent_rule', {}).get('company')),
('group', '=', Eval('group')),
['OR',
('group', '=', None),
If(Eval('_parent_rule', {}).get('kind', 'both') == 'sale',
('group.kind', 'in', ['sale', 'both']),
If(Eval('_parent_rule', {}).get('kind', 'both') ==
'purchase',
('group.kind', 'in', ['purchase', 'both']),
('group.kind', 'in', ['sale', 'purchase', 'both']))),
],
],
depends=['group'],
ondelete='RESTRICT')
sequence = fields.Integer('Sequence')
template = fields.Many2One('account.tax.rule.line.template', 'Template')
@classmethod
def __setup__(cls):
super(TaxRuleLine, cls).__setup__()
cls._order.insert(0, ('rule', 'ASC'))
cls._order.insert(0, ('sequence', 'ASC'))
@classmethod
def __register__(cls, module_name):
TableHandler = backend.get('TableHandler')
cursor = Transaction().cursor
table = TableHandler(cursor, cls, module_name)
super(TaxRuleLine, cls).__register__(module_name)
# Migration from 2.4: drop required on sequence
table.not_null_action('sequence', action='remove')
@staticmethod
def order_sequence(tables):
table, _ = tables[None]
return [table.sequence == None, table.sequence]
def match(self, pattern):
if 'group' in pattern and not self.group:
if pattern['group']:
return False
return super(TaxRuleLine, self).match(pattern)
def get_taxes(self):
'''
Return list of taxes for a line
'''
if self.tax:
return [self.tax.id]
return None
def update_rule_line(self, template2tax, template2rule,
template2rule_line=None):
'''
Update tax rule line based on template.
template2tax is a dictionary with tax template id as key and tax id as
value, used to convert template id into tax.
template2rule is a dictionary with tax rule template id as key and tax
rule id as value, used to convert template id into tax rule.
template2rule_line is a dictionary with tax rule line template id as
key and tax rule line id as value, used to convert template id into tax
rule line. The dictionary is filled with new tax rule lines.
'''
if template2rule_line is None:
template2rule_line = {}
if self.template:
vals = self.template._get_tax_rule_line_value(rule_line=self)
if self.rule.id != template2rule[self.template.rule.id]:
vals['rule'] = template2rule[self.template.rule.id]
if self.origin_tax:
if self.template.origin_tax:
if (self.origin_tax.id !=
template2tax[self.template.origin_tax.id]):
vals['origin_tax'] = template2tax[
self.template.origin_tax.id]
else:
vals['origin_tax'] = None
elif self.template.origin_tax:
vals['origin_tax'] = template2tax[self.template.origin_tax.id]
if self.tax:
if self.template.tax:
if self.tax.id != template2tax[self.template.tax.id]:
vals['tax'] = template2tax[self.template.tax.id]
else:
vals['tax'] = None
elif self.template.tax:
vals['tax'] = template2tax[self.template.tax.id]
if vals:
self.write([self], vals)
template2rule_line[self.template.id] = self.id
class OpenTaxCode(Wizard):
'Open Code'
__name__ = 'account.tax.open_code'
start_state = 'open_'
open_ = StateAction('account.act_tax_line_form')
def do_open_(self, action):
pool = Pool()
FiscalYear = pool.get('account.fiscalyear')
Period = pool.get('account.period')
if not Transaction().context.get('fiscalyear'):
fiscalyears = FiscalYear.search([
('state', '=', 'open'),
])
else:
fiscalyears = [FiscalYear(Transaction().context['fiscalyear'])]
periods = []
if not Transaction().context.get('periods'):
periods = Period.search([
('fiscalyear', 'in', [f.id for f in fiscalyears]),
])
else:
periods = Period.browse(Transaction().context['periods'])
action['pyson_domain'] = PYSONEncoder().encode([
('move_line.period', 'in', [p.id for p in periods]),
('code', '=', Transaction().context['active_id']),
])
if Transaction().context.get('fiscalyear'):
action['pyson_context'] = PYSONEncoder().encode({
'fiscalyear': Transaction().context['fiscalyear'],
})
else:
action['pyson_context'] = PYSONEncoder().encode({
'periods': [p.id for p in periods],
})
return action, {}
class AccountTemplateTaxTemplate(ModelSQL):
'Account Template - Tax Template'
__name__ = 'account.account.template-account.tax.template'
_table = 'account_account_template_tax_rel'
account = fields.Many2One('account.account.template', 'Account Template',
ondelete='CASCADE', select=True, required=True)
tax = fields.Many2One('account.tax.template', 'Tax Template',
ondelete='RESTRICT', select=True, required=True)
class AccountTemplate2:
__name__ = 'account.account.template'
taxes = fields.Many2Many('account.account.template-account.tax.template',
'account', 'tax', 'Default Taxes',
domain=[('parent', '=', None)])
class AccountTax(ModelSQL):
'Account - Tax'
__name__ = 'account.account-account.tax'
_table = 'account_account_tax_rel'
account = fields.Many2One('account.account', 'Account', ondelete='CASCADE',
select=True, required=True)
tax = fields.Many2One('account.tax', 'Tax', ondelete='RESTRICT',
select=True, required=True)
class Account2:
__name__ = 'account.account'
taxes = fields.Many2Many('account.account-account.tax',
'account', 'tax', 'Default Taxes',
domain=[
('company', '=', Eval('company')),
('parent', '=', None),
],
help=('Default tax for manual encoding of move lines \n'
'for journal types: "expense" and "revenue"'),
depends=['company'])
|