From 22566167fee80685af3b92f5a4232ffd1caa0799 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Valyi?= Date: Wed, 9 Jun 2010 19:22:51 -0300 Subject: [PATCH 001/153] merged useful tax logic modules from 5.0 branch (they are required for the Brazilian localization) --- .../__init__.py | 2 + .../__terp__.py | 33 ++++ .../account_product_fiscal_classification.py | 151 +++++++++++++++++ ...unt_product_fiscal_classification_data.xml | 16 ++ ...unt_product_fiscal_classification_view.xml | 117 +++++++++++++ .../i18n/pt_BR.po | 155 ++++++++++++++++++ .../product.py | 51 ++++++ .../product_view.xml | 18 ++ 8 files changed, 543 insertions(+) create mode 100644 account_product_fiscal_classification/__init__.py create mode 100755 account_product_fiscal_classification/__terp__.py create mode 100644 account_product_fiscal_classification/account_product_fiscal_classification.py create mode 100644 account_product_fiscal_classification/account_product_fiscal_classification_data.xml create mode 100644 account_product_fiscal_classification/account_product_fiscal_classification_view.xml create mode 100644 account_product_fiscal_classification/i18n/pt_BR.po create mode 100644 account_product_fiscal_classification/product.py create mode 100644 account_product_fiscal_classification/product_view.xml diff --git a/account_product_fiscal_classification/__init__.py b/account_product_fiscal_classification/__init__.py new file mode 100644 index 000000000..392654683 --- /dev/null +++ b/account_product_fiscal_classification/__init__.py @@ -0,0 +1,2 @@ +import account_product_fiscal_classification +import product \ No newline at end of file diff --git a/account_product_fiscal_classification/__terp__.py b/account_product_fiscal_classification/__terp__.py new file mode 100755 index 000000000..2d8a10a10 --- /dev/null +++ b/account_product_fiscal_classification/__terp__.py @@ -0,0 +1,33 @@ +# -*- encoding: utf-8 -*- +######################################################################### +# # +# Copyright (C) 2010 Raphaël Valyi # +# # +#This program is free software: you can redistribute it and/or modify # +#it under the terms of the GNU 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 General Public License for more details. # +# # +#You should have received a copy of the GNU General Public License # +#along with this program. If not, see . # +######################################################################### + +{ + "name" : "Account Product Fiscal Classification", + "version" : "0.1", + "author" : "Akretion", + "description": """Account Product Fiscal Classification + """, + 'website': 'http://www.akretion.com', + 'depends': ["account", "product"], + 'init_xml': [], + 'update_xml': ['product_view.xml', 'account_product_fiscal_classification_data.xml', 'account_product_fiscal_classification_view.xml', ], + 'demo_xml': [], + 'installable': True, + 'active': False, +} diff --git a/account_product_fiscal_classification/account_product_fiscal_classification.py b/account_product_fiscal_classification/account_product_fiscal_classification.py new file mode 100644 index 000000000..828db4fad --- /dev/null +++ b/account_product_fiscal_classification/account_product_fiscal_classification.py @@ -0,0 +1,151 @@ +# -*- encoding: utf-8 -*- +######################################################################### +# # +# Copyright (C) 2010 Raphaël Valyi # +# # +#This program is free software: you can redistribute it and/or modify # +#it under the terms of the GNU 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 General Public License for more details. # +# # +#You should have received a copy of the GNU General Public License # +#along with this program. If not, see . # +######################################################################### + +from osv import fields, osv + +class account_product_fiscal_classification(osv.osv): + _name = 'account.product.fiscal.classification' + _description = 'Product Fiscal Classification' + _columns = { + 'name': fields.char('Main code', size=32, required=True), + 'description': fields.char('Description', size=64), + 'company_id': fields.many2one('res.company', 'Company'), + #TODO restrict to company_id if company_id set when framework will allow it: + 'sale_base_tax_ids': fields.many2many('account.tax', 'fiscal_classification_sale_tax_rel', 'fiscal_classification_id', 'tax_id', 'Base Sale Taxes', domain=[('type_tax_use','!=','purchase')]), + 'purchase_base_tax_ids': fields.many2many('account.tax', 'fiscal_classification_purchase_tax_rel', 'fiscal_classification_id', 'tax_id', 'Base Purchase Taxes', domain=[('type_tax_use','!=','sale')]), + } + + def name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=80): + if not args: + args = [] + if not context: + context = {} + if name: + ids = self.search(cr, user, [('name', '=', name)] + args, limit=limit, context=context) + if not len(ids): + ids = self.search(cr, user, [('description', '=', name)] + args, limit=limit, context=context) + if not len(ids): + ids = self.search(cr, user, [('name', operator, name)] + args, limit=limit, context=context) + ids += self.search(cr, user, [('description', operator, name)] + args, limit=limit, context=context) + else: + ids = self.search(cr, user, args, limit=limit, context=context) + return self.name_get(cr, user, ids, context) + +account_product_fiscal_classification() + +class account_product_fiscal_classification_template(osv.osv): + _name = 'account.product.fiscal.classification.template' + _description = 'Product Fiscal Classification Template' + _columns = { + 'name': fields.char('Main code', size=32, required=True), + 'description': fields.char('Description', size=64), + #TODO restrict to company_id if company_id set when framework will allow it: + 'sale_base_tax_ids': fields.many2many('account.tax.template', 'fiscal_classification_template_sale_tax_rel', 'fiscal_classification_id', 'tax_id', 'Base Sale Taxes', domain=[('type_tax_use','!=','purchase')]), + 'purchase_base_tax_ids': fields.many2many('account.tax.template', 'fiscal_classification_template_purchase_tax_rel', 'fiscal_classification_id', 'tax_id', 'Base Purchase Taxes', domain=[('type_tax_use','!=','sale')]), + } + + def name_search(self, cr, user, name='', args=None, operator='ilike', context=None, limit=80): + if not args: + args = [] + if not context: + context = {} + if name: + ids = self.search(cr, user, [('name', '=', name)] + args, limit=limit, context=context) + if not len(ids): + ids = self.search(cr, user, [('description', '=', name)] + args, limit=limit, context=context) + if not len(ids): + ids = self.search(cr, user, [('name', operator, name)] + args, limit=limit, context=context) + ids += self.search(cr, user, [('description', operator, name)] + args, limit=limit, context=context) + else: + ids = self.search(cr, user, args, limit=limit, context=context) + return self.name_get(cr, user, ids, context) + +account_product_fiscal_classification_template() + +class wizard_account_product_fiscal_classification(osv.osv_memory): + + _name='wizard.account.product.fiscal.classification' + + _columns = { + 'company_id':fields.many2one('res.company','Company',required=True), + } + + _defaults = { + 'company_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr,uid,[uid],c)[0].company_id.id, + } + + def action_create(self, cr, uid, ids, context=None): + obj_wizard = self.browse(cr,uid,ids[0]) + obj_tax = self.pool.get('account.tax') + obj_tax_template = self.pool.get('account.tax.template') + obj_fiscal_classification = self.pool.get('account.product.fiscal.classification') + obj_fiscal_classification_template = self.pool.get('account.product.fiscal.classification.template') + + company_id = obj_wizard.company_id.id + tax_template_ref = {} + + tax_ids = obj_tax.search(cr,uid,[('company_id','=',company_id)]) + + for tax in obj_tax.browse(cr,uid,tax_ids): + tax_template = obj_tax_template.search(cr,uid,[('name','=',tax.name)])[0] + + if tax_template: + tax_template_ref[tax_template] = tax.id + + fclass_ids_template = obj_fiscal_classification_template.search(cr, uid, []) + + for fclass_template in obj_fiscal_classification_template.browse(cr, uid, fclass_ids_template): + + fclass_id = obj_fiscal_classification.search(cr, uid, [('name','=',fclass_template.name)]) + + if not fclass_id: + sale_tax_ids = [] + for tax in fclass_template.sale_base_tax_ids: + sale_tax_ids.append(tax_template_ref[tax.id]) + + purchase_tax_ids = [] + for tax in fclass_template.purchase_base_tax_ids: + purchase_tax_ids.append(tax_template_ref[tax.id]) + + vals = { + 'name': fclass_template.name, + 'description': fclass_template.description, + 'company_id': company_id, + 'sale_base_tax_ids': [(6,0,sale_tax_ids)], + 'purchase_base_tax_ids': [(6,0,purchase_tax_ids)] + } + obj_fiscal_classification.create(cr,uid,vals) + + return { + 'view_type': 'form', + "view_mode": 'form', + 'res_model': 'ir.actions.configuration.wizard', + 'type': 'ir.actions.act_window', + 'target':'new', + } + def action_cancel(self,cr,uid,ids,conect=None): + return { + 'view_type': 'form', + "view_mode": 'form', + 'res_model': 'ir.actions.configuration.wizard', + 'type': 'ir.actions.act_window', + 'target':'new', + } + +wizard_account_product_fiscal_classification() diff --git a/account_product_fiscal_classification/account_product_fiscal_classification_data.xml b/account_product_fiscal_classification/account_product_fiscal_classification_data.xml new file mode 100644 index 000000000..15bae7765 --- /dev/null +++ b/account_product_fiscal_classification/account_product_fiscal_classification_data.xml @@ -0,0 +1,16 @@ + + + + + + Product Fiscal Classification + + + + + ['|', ['company_id', '=', user.company_id.id], ['company_id','=', False]] + + + + + diff --git a/account_product_fiscal_classification/account_product_fiscal_classification_view.xml b/account_product_fiscal_classification/account_product_fiscal_classification_view.xml new file mode 100644 index 000000000..e5da193e5 --- /dev/null +++ b/account_product_fiscal_classification/account_product_fiscal_classification_view.xml @@ -0,0 +1,117 @@ + + + + + + fiscal_classification_normal_form_view_form + account.product.fiscal.classification + form + +
+ + + + + + + + + + +
+ + + fiscal_classification_normal_form_view_tree + account.product.fiscal.classification + tree + + + + + + + + + + + fiscal_classification_normal_form_view_form + account.product.fiscal.classification.template + form + +
+ + + + + + + + + +
+ + + fiscal_classification_normal_form_view_tree + account.product.fiscal.classification.template + tree + + + + + + + + + + + + Generate Product Fiscal Classification from Templates + wizard.account.product.fiscal.classification + form + +
+ +