1
1
# -*- encoding: utf-8 -*-
2
#################################################################################
4
# Copyright (C) 2009 Renato Lima - Akretion #
6
#This program is free software: you can redistribute it and/or modify #
7
#it under the terms of the GNU Affero General Public License as published by #
8
#the Free Software Foundation, either version 3 of the License, or #
9
#(at your option) any later version. #
11
#This program is distributed in the hope that it will be useful, #
12
#but WITHOUT ANY WARRANTY; without even the implied warranty of #
13
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14
#GNU Affero General Public License for more details. #
16
#You should have received a copy of the GNU Affero General Public License #
17
#along with this program. If not, see <http://www.gnu.org/licenses/>. #
18
#################################################################################
2
###############################################################################
4
# Copyright (C) 2009 Renato Lima - Akretion #
6
#This program is free software: you can redistribute it and/or modify #
7
#it under the terms of the GNU Affero General Public License as published by #
8
#the Free Software Foundation, either version 3 of the License, or #
9
#(at your option) any later version. #
11
#This program is distributed in the hope that it will be useful, #
12
#but WITHOUT ANY WARRANTY; without even the implied warranty of #
13
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
14
#GNU Affero General Public License for more details. #
16
#You should have received a copy of the GNU Affero General Public License #
17
#along with this program. If not, see <http://www.gnu.org/licenses/>. #
18
###############################################################################
20
20
from lxml import etree
1054
1061
'ii_customhouse_charges': fields.float(
1055
1062
'Depesas Atuaneiras', required=True,
1056
1063
digits_compute=dp.get_precision('Account'))}
1060
1067
'ii_customhouse_charges': 0.0}
1062
1069
def _fiscal_position_map(self, cr, uid, ids, partner_id,
1063
partner_invoice_id, company_id, fiscal_category_id):
1070
partner_invoice_id, company_id,
1071
fiscal_category_id, product_id=False,
1072
account_id=False, context=False):
1064
1073
result = {'cfop_id': False}
1065
1074
obj_rule = self.pool.get('account.fiscal.position.rule')
1066
fiscal_result = obj_rule.fiscal_position_map(cr, uid, partner_id, partner_invoice_id, company_id, fiscal_category_id, context={'use_domain': ('use_invoice','=',True)})
1075
fiscal_result = obj_rule.fiscal_position_map(
1076
cr, uid, partner_id, partner_invoice_id, company_id,
1078
context={'use_domain': ('use_invoice', '=', True)})
1067
1079
result.update(fiscal_result)
1068
1080
if result.get('fiscal_position', False):
1069
obj_fp = self.pool.get('account.fiscal.position').browse(cr, uid, result['fiscal_position'])
1070
result['cfop_id'] = obj_fp.cfop_id.id
1081
obj_fposition = self.pool.get('account.fiscal.position').browse(
1082
cr, uid, result['fiscal_position'])
1083
result['cfop_id'] = obj_fposition.cfop_id.id
1085
obj_product = self.pool.get('product.product').browse(
1086
cr, uid, product_id, context=context)
1087
if context.get('type') in ('out_invoice', 'out_refund'):
1088
taxes = obj_product.taxes_id and obj_product.taxes_id or (account_id and self.pool.get('account.account').browse(cr, uid, account_id, context=context).tax_ids or False)
1090
taxes = obj_product.supplier_taxes_id and obj_product.supplier_taxes_id or (account_id and self.pool.get('account.account').browse(cr, uid, account_id, context=context).tax_ids or False)
1092
tax_ids = self.pool.get('account.fiscal.position').map_tax(
1093
cr, uid, obj_fposition, taxes)
1095
result['invoice_line_tax_id'] = tax_ids
1073
1099
def product_id_change(self, cr, uid, ids, product, uom, qty=0, name='',
1074
type='out_invoice', partner_id=False, fposition_id=False,
1075
price_unit=False, address_invoice_id=False, currency_id=False,
1076
context=None, company_id=False, fiscal_category_id=False, parent_fposition_id=False):
1100
type='out_invoice', partner_id=False,
1101
fposition_id=False, price_unit=False,
1102
address_invoice_id=False, currency_id=False,
1103
context=None, company_id=False,
1104
fiscal_category_id=False, parent_fposition_id=False):
1077
1106
result = super(account_invoice_line, self).product_id_change(
1078
1107
cr, uid, ids, product, uom, qty, name, type, partner_id,
1079
1108
fposition_id, price_unit, address_invoice_id, currency_id,
1080
1109
context, company_id)
1082
1111
if not fiscal_category_id or not product or not parent_fposition_id:
1086
1115
product_fiscal_category_id = obj_fp_rule.product_fiscal_category_map(
1087
1116
cr, uid, product, fiscal_category_id)
1089
fiscal_position = fposition_id or parent_fposition_id or False
1118
fiscal_position = parent_fposition_id or False
1091
1120
if not product_fiscal_category_id:
1092
1121
result['value']['fiscal_category_id'] = fiscal_category_id
1093
result['value']['fiscal_position_id'] = fiscal_position
1122
result['value']['fiscal_position'] = fiscal_position
1094
1123
if fiscal_position:
1095
1124
result['value']['cfop_id'] = self.pool.get('account.fiscal.position').read(cr, uid, [fiscal_position], ['cfop_id'])[0]['cfop_id']
1097
1126
result['value']['fiscal_category_id'] = product_fiscal_category_id
1098
fiscal_data = self._fiscal_position_map(cr, uid, ids, partner_id, address_invoice_id, company_id, product_fiscal_category_id)
1127
fiscal_data = self._fiscal_position_map(
1128
cr, uid, ids, partner_id, address_invoice_id, company_id,
1129
product_fiscal_category_id, product,
1130
result['value'].get('account_id', False), context)
1099
1131
result['value'].update(fiscal_data)
1135
def onchange_fiscal_category_id(self, cr, uid, ids, partner_id,
1136
address_invoice_id, company_id, product_id,
1137
fiscal_category_id, account_id, context):
1138
result = {'value': {}}
1139
fiscal_data = self._fiscal_position_map(
1140
cr, uid, ids, partner_id, address_invoice_id, company_id,
1141
fiscal_category_id, product_id, account_id, context)
1143
result['value'].update(fiscal_data)
1146
def onchange_fiscal_position(self, cr, uid, ids, partner_id,
1147
address_invoice_id, company_id, product_id,
1148
fiscal_category_id, account_id, context):
1149
result = {'value': {}}
1150
fiscal_data = self._fiscal_position_map(
1151
cr, uid, ids, partner_id, address_invoice_id, company_id,
1152
fiscal_category_id, product_id, account_id, context)
1154
result['value'].update(fiscal_data)
1103
1157
account_invoice_line()