diff --git a/sale_fiscal_position_update_button/__init__.py b/sale_fiscal_position_update_button/__init__.py new file mode 100644 index 0000000..7b6196c --- /dev/null +++ b/sale_fiscal_position_update_button/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Sale Fiscal Position Update Button module for OpenERP +# Copyright (C) 2014 Akretion (http://www.akretion.com) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from . import sale diff --git a/sale_fiscal_position_update_button/__openerp__.py b/sale_fiscal_position_update_button/__openerp__.py new file mode 100644 index 0000000..b3e3c08 --- /dev/null +++ b/sale_fiscal_position_update_button/__openerp__.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# Sale Fiscal Position Update Button module for OpenERP +# Copyright (C) 2011-2014 Julius Network Solutions SARL +# Copyright (C) 2014 Akretion (http://www.akretion.com) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +{ + 'name': 'Sale Fiscal Position Update Button', + 'version': '1.0', + 'category': 'Sales Management', + 'license': 'AGPL-3', + 'summary': 'Update the fiscal position of a sale order in one click', + 'description': """ +Sale Fiscal Position Update Button +================================== + +When the sale order is in draft/sent state, you can change the fiscal position and click on a button *Update Tax* to update the taxes on all the sale order lines which have a product (if a sale order line doesn't have a product, it won't work and the user will have an error message). + +This module is an alternative to the module sale_fiscal_position_update from the sale-wkfl OCA branch, which works with an on_change. It is particularly usefull when a country updates it's VAT rates and the salesman want to update their quote and have the new VAT rates in one click. +""", + 'author': 'Julius Network Solutions, Akretion', + 'depends': ['sale'], + 'data': ['sale_view.xml'], + 'installable': True, + 'active': False, +} diff --git a/sale_fiscal_position_update_button/sale.py b/sale_fiscal_position_update_button/sale.py new file mode 100644 index 0000000..1b2602b --- /dev/null +++ b/sale_fiscal_position_update_button/sale.py @@ -0,0 +1,58 @@ +# -*- coding: utf-8 -*- +############################################################################# +# +# Sale Fiscal Position Update module for OpenERP +# Copyright (C) 2011-2014 Julius Network Solutions SARL +# Copyright (C) 2014 Akretion (http://www.akretion.com) +# @author Mathieu Vatel +# @author Alexis de Lattre +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +from openerp.osv import orm +from openerp.tools.translate import _ + + +class sale_order(orm.Model): + _inherit = "sale.order" + + def update_fiscal_position(self, cr, uid, ids, context=None): + '''Function executed by the "(update)" button on orders + If the orders are in draft state, it updates taxes and accounts + on all order lines''' + fp_obj = self.pool['account.fiscal.position'] + for order in self.browse(cr, uid, ids, context=context): + if order.state not in ('sent', 'draft'): + raise orm.except_orm( + _('Error:'), + _('You cannot update the fiscal position because the ' + 'sale order is not in draft or sent state.')) + fp = order.fiscal_position + for line in order.order_line: + if line.product_id: + product = self.pool['product.product'].browse( + cr, uid, line.product_id.id, context=context) + taxes = product.taxes_id + tax_ids = fp_obj.map_tax( + cr, uid, fp, taxes, context=context) + line.write({'tax_id': [(6, 0, tax_ids)]}, context=context) + else: + raise orm.except_orm( + _('Error:'), + _("Cannot update the fiscal position because " + "the line '%s' doesn't have a product.") + % line.name) + return {} diff --git a/sale_fiscal_position_update_button/sale_view.xml b/sale_fiscal_position_update_button/sale_view.xml new file mode 100644 index 0000000..28e1dae --- /dev/null +++ b/sale_fiscal_position_update_button/sale_view.xml @@ -0,0 +1,19 @@ + + + + + + fiscal.position.update.button.order.form + sale.order + + + +