~openerp-commiter/openobject-addons/extra-6.0

« back to all changes in this revision

Viewing changes to account_product_fiscal_classification/product.py

  • Committer: Raphaël Valyi
  • Date: 2010-06-09 22:22:51 UTC
  • mto: This revision was merged to the branch mainline in revision 4608.
  • Revision ID: rvalyi@gmail.com-20100609222251-wordxv1le40jkbpe
[MERGE] merged useful tax logic modules from 5.0 branch (they are required for the Brazilian localization)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
#########################################################################
 
3
#                                                                       #
 
4
# Copyright (C) 2009  Rapha�l Valyi                                     #
 
5
#                                                                       #
 
6
#This program is free software: you can redistribute it and/or modify   #
 
7
#it under the terms of the GNU 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.                                    #
 
10
#                                                                       #
 
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 General Public License for more details.                           #
 
15
#                                                                       #
 
16
#You should have received a copy of the GNU General Public License      #
 
17
#along with this program.  If not, see <http://www.gnu.org/licenses/>.  #
 
18
#########################################################################
 
19
 
 
20
from osv import fields, osv
 
21
 
 
22
class product_product(osv.osv):
 
23
    _inherit = 'product.product'
 
24
    _columns = {
 
25
                'property_fiscal_classification': fields.property(
 
26
                    'account.product.fiscal.classification',
 
27
                    type='many2one',
 
28
                    relation='account.product.fiscal.classification',
 
29
                    string="Fiscal Classification",
 
30
                    method=True,
 
31
                    view_load=True,
 
32
                    help="Company wise (eg localizable) Fiscal Classification"),
 
33
                }
 
34
 
 
35
    def fiscal_classification_id_change(self, cr, uid, ids, fiscal_classification_id=False, sale_tax_ids=[[6, 0, []]], purchase_tax_ids=[[6, 0, []]]):
 
36
        """We eventually keep the sale and purchase taxes because those are not company wise in OpenERP. So if we choose a different fiscal position
 
37
        for a different company, we don't want to override other's companies setting"""
 
38
        result = {'value':{}}
 
39
        if fiscal_classification_id:
 
40
            fiscal_classification = self.pool.get('account.product.fiscal.classification').browse(cr, uid, fiscal_classification_id)
 
41
            
 
42
            current_company_id = self.pool.get('res.users').browse(cr, uid, uid).company_id.partner_id.id
 
43
            to_keep_sale_tax_ids = self.pool.get('account.tax').search(cr, uid, [('id', 'in', sale_tax_ids[0][2]), ('company_id', '!=', current_company_id)])
 
44
            to_keep_purchase_tax_ids = self.pool.get('account.tax').search(cr, uid, [('id', 'in', purchase_tax_ids[0][2]), ('company_id', '!=', current_company_id)])
 
45
            
 
46
            result['value']['taxes_id'] = to_keep_sale_tax_ids + [x.id for x in fiscal_classification.sale_base_tax_ids]
 
47
            result['value']['supplier_taxes_id'] = to_keep_purchase_tax_ids + [x.id for x in fiscal_classification.purchase_base_tax_ids]
 
48
            
 
49
        return result
 
50
            
 
51
product_product()
 
 
b'\\ No newline at end of file'