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

« back to all changes in this revision

Viewing changes to account_fiscal_position_rule/account_fiscal_position_rule.py

  • Committer: Renato Lima
  • Date: 2010-07-23 13:30:48 UTC
  • Revision ID: renato@renato-laptop-20100723133048-i1eg8cowzjfzgwd5
Added new module account_fiscal_position_rule

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    OpenERP, Open Source Management Solution
 
5
#    Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
 
6
#    $Id$
 
7
#
 
8
#    This program is free software: you can redistribute it and/or modify
 
9
#    it under the terms of the GNU General Public License as published by
 
10
#    the Free Software Foundation, either version 3 of the License, or
 
11
#    (at your option) any later version.
 
12
#
 
13
#    This program is distributed in the hope that it will be useful,
 
14
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
15
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
16
#    GNU General Public License for more details.
 
17
#
 
18
#    You should have received a copy of the GNU General Public License
 
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
20
#
 
21
##############################################################################
 
22
 
 
23
from osv import fields, osv
 
24
 
 
25
class account_fiscal_position_rule(osv.osv):
 
26
    _name = "account.fiscal.position.rule"
 
27
    _columns = {
 
28
        'name': fields.char('Name', size=64, required=True),
 
29
        'description': fields.char('Description', size=128),
 
30
        'from_country': fields.many2one('res.country','Country Form'),
 
31
        'from_state': fields.many2one('res.country.state', 'State To', domain="[('country_id','=',from_country)]"),
 
32
        'to_country': fields.many2one('res.country', 'Country To'),
 
33
        'to_state': fields.many2one('res.country.state', 'State To', domain="[('country_id','=',to_country)]"),
 
34
        'company_id': fields.many2one('res.company', 'Company', required=True),
 
35
        'fiscal_position_id': fields.many2one('account.fiscal.position', 'Fiscal Position', domain="[('company_id','=',company_id)]", required=True),
 
36
        'use_sale' : fields.boolean('Use in sales order'),
 
37
        'use_invoice' : fields.boolean('Use in Invoices'),
 
38
    }
 
39
account_fiscal_position_rule()
 
40
 
 
41
class account_fiscal_position_rule_template(osv.osv):
 
42
    _name = "account.fiscal.position.rule.template"
 
43
    _columns = {
 
44
        'name': fields.char('Name', size=64, required=True),
 
45
        'description': fields.char('Description', size=128),
 
46
        'from_country': fields.many2one('res.country','Country Form'),
 
47
        'from_state': fields.many2one('res.country.state', 'State From', domain="[('country_id','=',from_country)]"),
 
48
        'to_country': fields.many2one('res.country', 'Country To'),
 
49
        'to_state': fields.many2one('res.country.state', 'State To', domain="[('country_id','=',to_country)]"),
 
50
        'fiscal_position_id': fields.many2one('account.fiscal.position.template', 'Fiscal Position', required=True),
 
51
        'use_sale' : fields.boolean('Use in sales order'),
 
52
        'use_invoice' : fields.boolean('Use in Invoices'),
 
53
    }
 
54
account_fiscal_position_rule_template()
 
55
 
 
56
class wizard_account_fiscal_position_rule(osv.osv_memory):
 
57
    _name='wizard.account.fiscal.position.rule'
 
58
    
 
59
    _columns = {
 
60
        'company_id':fields.many2one('res.company','Company',required=True),
 
61
    }
 
62
    
 
63
    _defaults = {
 
64
        'company_id': lambda self, cr, uid, c: self.pool.get('res.users').browse(cr,uid,[uid],c)[0].company_id.id,
 
65
    }
 
66
 
 
67
    def action_create(self, cr, uid, ids, context=None):
 
68
        obj_wizard = self.browse(cr,uid,ids[0])
 
69
        obj_fiscal_position_rule = self.pool.get('account.fiscal.position.rule')
 
70
        obj_fiscal_position_rule_template = self.pool.get('account.fiscal.position.rule.template')
 
71
 
 
72
        company_id = obj_wizard.company_id.id
 
73
        
 
74
        pfr_ids = obj_fiscal_position_rule_template.search(cr, uid, [])
 
75
        
 
76
        for fpr_template in obj_fiscal_position_rule_template.browse(cr, uid, pfr_ids):
 
77
            vals = {
 
78
                    'name': fpr_template.name,
 
79
                    'description': fpr_template.description,
 
80
                    'from_country': fpr_template.from_country.id,
 
81
                    'from_state': fpr_template.from_state.id,
 
82
                    'to_country': fpr_template.to_country.id,
 
83
                    'to_state': fpr_template.to_state.id,
 
84
                    'company_id': company_id,
 
85
                    'fiscal_position_id': fpr_template.fiscal_position_id.id,
 
86
                    'fiscal_operaton_id': fpr_template.fiscal_operation_id.id,
 
87
                    'use_sale' : fpr_template.use_sale,
 
88
                    'use_invoice' : fpr_template.use_invoice
 
89
                    }
 
90
            obj_fiscal_position_rule.create(cr,uid,vals)
 
91
 
 
92
        return {
 
93
                'view_type': 'form',
 
94
                "view_mode": 'form',
 
95
                'res_model': 'ir.actions.configuration.wizard',
 
96
                'type': 'ir.actions.act_window',
 
97
                'target':'new',
 
98
        }
 
99
    def action_cancel(self,cr,uid,ids,conect=None):
 
100
        return {
 
101
                'view_type': 'form',
 
102
                "view_mode": 'form',
 
103
                'res_model': 'ir.actions.configuration.wizard',
 
104
                'type': 'ir.actions.act_window',
 
105
                'target':'new',
 
106
        }
 
107
 
 
108
 
 
109
wizard_account_fiscal_position_rule()
 
 
b'\\ No newline at end of file'