OLD | NEW |
1 #This file is part of Tryton. The COPYRIGHT file at the top level of | 1 #This file is part of Tryton. The COPYRIGHT file at the top level of |
2 #this repository contains the full copyright notices and license terms. | 2 #this repository contains the full copyright notices and license terms. |
3 "Tax" | 3 "Tax" |
4 from trytond.model import ModelView, ModelSQL, fields | 4 from trytond.model import ModelView, ModelSQL, fields |
5 from trytond.wizard import Wizard | 5 from trytond.wizard import Wizard |
6 from decimal import Decimal | 6 from decimal import Decimal |
7 from trytond.tools import Cache | 7 from trytond.tools import Cache |
8 from trytond.backend import TableHandler | 8 from trytond.backend import TableHandler |
9 | 9 |
10 | 10 |
(...skipping 933 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
944 rule_line_obj = self.pool.get('account.tax.rule.line') | 944 rule_line_obj = self.pool.get('account.tax.rule.line') |
945 | 945 |
946 if isinstance(rule, (int, long)): | 946 if isinstance(rule, (int, long)): |
947 rule = self.browse(cursor, user, rule, context=context) | 947 rule = self.browse(cursor, user, rule, context=context) |
948 | 948 |
949 if isinstance(tax, (int, long)): | 949 if isinstance(tax, (int, long)): |
950 tax = tax_obj.browse(cursor, user, tax, context=context) | 950 tax = tax_obj.browse(cursor, user, tax, context=context) |
951 | 951 |
952 pattern = pattern.copy() | 952 pattern = pattern.copy() |
953 pattern['group'] = tax and tax.group.id or False | 953 pattern['group'] = tax and tax.group.id or False |
| 954 pattern['origin_tax'] = tax and tax.id or False |
954 | 955 |
955 for line in rule.lines: | 956 for line in rule.lines: |
956 if rule_line_obj.match(cursor, user, line, pattern, | 957 if rule_line_obj.match(cursor, user, line, pattern, |
957 context=context): | 958 context=context): |
958 return rule_line_obj.get_taxes(cursor, user, line, | 959 return rule_line_obj.get_taxes(cursor, user, line, |
959 context=context) | 960 context=context) |
960 return tax and [tax.id] or False | 961 return tax and [tax.id] or False |
961 | 962 |
962 def update_rule(self, cursor, user, rule, context=None, template2rule=None): | 963 def update_rule(self, cursor, user, rule, context=None, template2rule=None): |
963 ''' | 964 ''' |
(...skipping 25 matching lines...) Expand all Loading... |
989 Rule() | 990 Rule() |
990 | 991 |
991 | 992 |
992 class RuleLineTemplate(ModelSQL, ModelView): | 993 class RuleLineTemplate(ModelSQL, ModelView): |
993 'Tax Rule Line Template' | 994 'Tax Rule Line Template' |
994 _name = 'account.tax.rule.line.template' | 995 _name = 'account.tax.rule.line.template' |
995 _description = __doc__ | 996 _description = __doc__ |
996 rule = fields.Many2One('account.tax.rule.template', 'Rule', required=True, | 997 rule = fields.Many2One('account.tax.rule.template', 'Rule', required=True, |
997 ondelete='CASCADE') | 998 ondelete='CASCADE') |
998 group = fields.Many2One('account.tax.group', 'Tax Group') | 999 group = fields.Many2One('account.tax.group', 'Tax Group') |
| 1000 origin_tax = fields.Many2One('account.tax.template', 'Original Tax', |
| 1001 domain="[('account', '=', _parent_rule.account), " \ |
| 1002 "('group', '=', group)]", |
| 1003 help='If the original tax template is filled, the rule will be ' \ |
| 1004 'applied only for this tax template.') |
999 tax = fields.Many2One('account.tax.template', 'Substitution Tax', | 1005 tax = fields.Many2One('account.tax.template', 'Substitution Tax', |
1000 domain="[('account', '=', _parent_rule.account), " \ | 1006 domain="[('account', '=', _parent_rule.account), " \ |
1001 "('group', '=', group)]") | 1007 "('group', '=', group)]") |
1002 sequence = fields.Integer('Sequence') | 1008 sequence = fields.Integer('Sequence') |
1003 | 1009 |
1004 def __init__(self): | 1010 def __init__(self): |
1005 super(RuleLineTemplate, self).__init__() | 1011 super(RuleLineTemplate, self).__init__() |
1006 self._order.insert(0, ('rule', 'ASC')) | 1012 self._order.insert(0, ('rule', 'ASC')) |
1007 self._order.insert(0, ('sequence', 'ASC')) | 1013 self._order.insert(0, ('sequence', 'ASC')) |
1008 | 1014 |
1009 def _get_tax_rule_line_value(self, cursor, user, template, context=None, | 1015 def _get_tax_rule_line_value(self, cursor, user, template, context=None, |
1010 rule_line=None): | 1016 rule_line=None): |
1011 ''' | 1017 ''' |
1012 Set values for tax rule line creation. | 1018 Set values for tax rule line creation. |
1013 | 1019 |
1014 :param cursor: the database cursor | 1020 :param cursor: the database cursor |
1015 :param user: the user id | 1021 :param user: the user id |
1016 :param template: the BrowseRecord of the template | 1022 :param template: the BrowseRecord of the template |
1017 :param context: the context | 1023 :param context: the context |
1018 :param rule_line: the BrowseRecord of the rule line to update | 1024 :param rule_line: the BrowseRecord of the rule line to update |
1019 :return: a dictionary with rule line fields as key and values as value | 1025 :return: a dictionary with rule line fields as key and values as value |
1020 ''' | 1026 ''' |
1021 res = {} | 1027 res = {} |
1022 if not rule_line or rule_line.group.id != template.group.id: | 1028 if not rule_line or rule_line.group.id != template.group.id: |
1023 res['group'] = template.group.id | 1029 res['group'] = template.group.id |
| 1030 if not rule_line or rule_line.origin_tax.id != template.origin_tax.id: |
| 1031 res['origin_tax'] = template.origin_tax.id |
1024 if not rule_line or rule_line.sequence != template.sequence: | 1032 if not rule_line or rule_line.sequence != template.sequence: |
1025 res['sequence'] = template.sequence | 1033 res['sequence'] = template.sequence |
1026 if not rule_line or rule_line.template.id != template.id: | 1034 if not rule_line or rule_line.template.id != template.id: |
1027 res['template'] = template.id | 1035 res['template'] = template.id |
1028 return res | 1036 return res |
1029 | 1037 |
1030 def create_rule_line(self, cursor, user, template, template2tax, | 1038 def create_rule_line(self, cursor, user, template, template2tax, |
1031 template2rule, context=None, template2rule_line=None): | 1039 template2rule, context=None, template2rule_line=None): |
1032 ''' | 1040 ''' |
1033 Create tax rule line based on template. | 1041 Create tax rule line based on template. |
(...skipping 20 matching lines...) Expand all Loading... |
1054 if template2rule_line is None: | 1062 if template2rule_line is None: |
1055 template2rule_line = {} | 1063 template2rule_line = {} |
1056 | 1064 |
1057 if isinstance(template, (int, long)): | 1065 if isinstance(template, (int, long)): |
1058 template = self.browse(cursor, user, template, context=context) | 1066 template = self.browse(cursor, user, template, context=context) |
1059 | 1067 |
1060 if template.id not in template2rule_line: | 1068 if template.id not in template2rule_line: |
1061 vals = self._get_tax_rule_line_value(cursor, user, template, | 1069 vals = self._get_tax_rule_line_value(cursor, user, template, |
1062 context=context) | 1070 context=context) |
1063 vals['rule'] = template2rule[template.rule.id] | 1071 vals['rule'] = template2rule[template.rule.id] |
| 1072 if template.origin_tax: |
| 1073 vals['origin_tax'] = template2tax[template.origin_tax.id] |
| 1074 else: |
| 1075 vals['origin_tax'] = False |
1064 if template.tax: | 1076 if template.tax: |
1065 vals['tax'] = template2tax[template.tax.id] | 1077 vals['tax'] = template2tax[template.tax.id] |
1066 else: | 1078 else: |
1067 vals['tax'] = False | 1079 vals['tax'] = False |
1068 new_id = rule_line_obj.create(cursor, user, vals, context=context) | 1080 new_id = rule_line_obj.create(cursor, user, vals, context=context) |
1069 template2rule_line[template.id] = new_id | 1081 template2rule_line[template.id] = new_id |
1070 else: | 1082 else: |
1071 new_id = template2rule_line[template.id] | 1083 new_id = template2rule_line[template.id] |
1072 return new_id | 1084 return new_id |
1073 | 1085 |
1074 RuleLineTemplate() | 1086 RuleLineTemplate() |
1075 | 1087 |
1076 | 1088 |
1077 class RuleLine(ModelSQL, ModelView): | 1089 class RuleLine(ModelSQL, ModelView): |
1078 'Tax Rule Line' | 1090 'Tax Rule Line' |
1079 _name = 'account.tax.rule.line' | 1091 _name = 'account.tax.rule.line' |
1080 _description = __doc__ | 1092 _description = __doc__ |
1081 _rec_name = 'tax' | 1093 _rec_name = 'tax' |
1082 rule = fields.Many2One('account.tax.rule', 'Rule', required=True, | 1094 rule = fields.Many2One('account.tax.rule', 'Rule', required=True, |
1083 select=1, ondelete='CASCADE') | 1095 select=1, ondelete='CASCADE') |
1084 group = fields.Many2One('account.tax.group', 'Tax Group') | 1096 group = fields.Many2One('account.tax.group', 'Tax Group') |
| 1097 origin_tax = fields.Many2One('account.tax', 'Original Tax', |
| 1098 domain="[('company', '=', _parent_rule.company), " \ |
| 1099 "('group', '=', group)]", |
| 1100 help='If the original tax is filled, the rule will be applied ' \ |
| 1101 'only for this tax.') |
1085 tax = fields.Many2One('account.tax', 'Substitution Tax', | 1102 tax = fields.Many2One('account.tax', 'Substitution Tax', |
1086 domain="[('company', '=', _parent_rule.company), " \ | 1103 domain="[('company', '=', _parent_rule.company), " \ |
1087 "('group', '=', group)]") | 1104 "('group', '=', group)]") |
1088 sequence = fields.Integer('Sequence') | 1105 sequence = fields.Integer('Sequence') |
1089 template = fields.Many2One('account.tax.rule.line.template', 'Template') | 1106 template = fields.Many2One('account.tax.rule.line.template', 'Template') |
1090 | 1107 |
1091 def __init__(self): | 1108 def __init__(self): |
1092 super(RuleLine, self).__init__() | 1109 super(RuleLine, self).__init__() |
1093 self._order.insert(0, ('rule', 'ASC')) | 1110 self._order.insert(0, ('rule', 'ASC')) |
1094 self._order.insert(0, ('sequence', 'ASC')) | 1111 self._order.insert(0, ('sequence', 'ASC')) |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1161 template2rule_line = {} | 1178 template2rule_line = {} |
1162 | 1179 |
1163 if isinstance(rule_line, (int, long)): | 1180 if isinstance(rule_line, (int, long)): |
1164 rule_line = self.browse(cursor, user, rule_line, context=context) | 1181 rule_line = self.browse(cursor, user, rule_line, context=context) |
1165 | 1182 |
1166 if rule_line.template: | 1183 if rule_line.template: |
1167 vals = template_obj._get_tax_rule_line_value(cursor, user, | 1184 vals = template_obj._get_tax_rule_line_value(cursor, user, |
1168 rule_line.template, context=context, rule_line=rule_line) | 1185 rule_line.template, context=context, rule_line=rule_line) |
1169 if rule_line.rule.id != template2rule[rule_line.template.rule.id]: | 1186 if rule_line.rule.id != template2rule[rule_line.template.rule.id]: |
1170 vals['rule'] = template2rule[rule_line.template.rule.id] | 1187 vals['rule'] = template2rule[rule_line.template.rule.id] |
| 1188 if rule_line.origin_tax: |
| 1189 if rule_line.template.origin_tax: |
| 1190 if rule_line.origin_tax.id != \ |
| 1191 template2tax[rule_line.template.origin_tax.id]: |
| 1192 vals['origin_tax'] = template2tax[ |
| 1193 rule_line.template.origin_tax.id] |
1171 if rule_line.tax: | 1194 if rule_line.tax: |
1172 if rule_line.template.tax: | 1195 if rule_line.template.tax: |
1173 if rule_line.tax.id != \ | 1196 if rule_line.tax.id != \ |
1174 template2tax[rule_line.template.tax.id]: | 1197 template2tax[rule_line.template.tax.id]: |
1175 vals['tax'] = template2tax[rule_line.template.tax.id] | 1198 vals['tax'] = template2tax[rule_line.template.tax.id] |
1176 if vals: | 1199 if vals: |
1177 self.write(cursor, user, rule_line.id, vals, context=context) | 1200 self.write(cursor, user, rule_line.id, vals, context=context) |
1178 template2rule_line[rule_line.template.id] = rule_line.id | 1201 template2rule_line[rule_line.template.id] = rule_line.id |
1179 | 1202 |
1180 RuleLine() | 1203 RuleLine() |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1276 class Account(ModelSQL, ModelView): | 1299 class Account(ModelSQL, ModelView): |
1277 _name = 'account.account' | 1300 _name = 'account.account' |
1278 taxes = fields.Many2Many('account.account-account.tax', | 1301 taxes = fields.Many2Many('account.account-account.tax', |
1279 'account', 'tax', 'Default Taxes', | 1302 'account', 'tax', 'Default Taxes', |
1280 domain="[('company', '=', company), ('parent', '=', False)]", | 1303 domain="[('company', '=', company), ('parent', '=', False)]", |
1281 help='Default tax for manual encoding of move lines \n' \ | 1304 help='Default tax for manual encoding of move lines \n' \ |
1282 'for journal types: "expense" and "revenue"', | 1305 'for journal types: "expense" and "revenue"', |
1283 depends=['company']) | 1306 depends=['company']) |
1284 | 1307 |
1285 Account() | 1308 Account() |
OLD | NEW |