~vauxoo/addons-vauxoo/7.0-user_story-rev4-kty

« back to all changes in this revision

Viewing changes to account_wizard_vouchers_invoice/account_voucher.py

  • Committer: jose at vauxoo
  • Date: 2013-07-25 20:54:29 UTC
  • mfrom: (659 vaddons-70)
  • mto: This revision was merged to the branch mainline in revision 820.
  • Revision ID: jose@vauxoo.com-20130725205429-tcrhjjc3og02uc0g
 
[MERGE] Merge from 7 Series to add the new features

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- encoding: utf-8 -*-
 
2
###########################################################################
 
3
#    Module Writen to OpenERP, Open Source Management Solution
 
4
#
 
5
#    Copyright (c) 2010 Vauxoo - http://www.vauxoo.com/
 
6
#    All Rights Reserved.
 
7
#    info Vauxoo (info@vauxoo.com)
 
8
############################################################################
 
9
#    Coded by: Luis Torres (luis_t@vauxoo.com)
 
10
############################################################################
 
11
#
 
12
#    This program is free software: you can redistribute it and/or modify
 
13
#    it under the terms of the GNU Affero General Public License as
 
14
#    published by the Free Software Foundation, either version 3 of the
 
15
#    License, or (at your option) any later version.
 
16
#
 
17
#    This program is distributed in the hope that it will be useful,
 
18
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
19
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
20
#    GNU Affero General Public License for more details.
 
21
#
 
22
#    You should have received a copy of the GNU Affero General Public License
 
23
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
24
#
 
25
##############################################################################
 
26
from openerp.osv import fields, osv
 
27
from lxml import etree
 
28
from openerp import SUPERUSER_ID
 
29
 
 
30
class account_voucher(osv.Model):
 
31
    _inherit = 'account.voucher'
 
32
    
 
33
    def fields_view_get_address(self, cr, uid, arch, context={}):
 
34
        user_obj = self.pool.get('res.users')
 
35
        fmt = user_obj.browse(cr, SUPERUSER_ID, uid, context).\
 
36
            company_id.country_id
 
37
        fmt = fmt and fmt.address_format
 
38
        layouts = {
 
39
            'new_div': """
 
40
                <div class="oe_subtotal_footer_separator">
 
41
                    <field name="conciled" modifiers="{&quot;invisible&quot;:\
 
42
                    true}"/>
 
43
                    <label for="amount"/>
 
44
                    <button type="object" icon="terp-stock_format-scientific" \
 
45
                        name="compute_tax" class="oe_link oe_edit_only" \
 
46
                        string="(Update)" attrs="{'invisible': \
 
47
                        [('state','!=','draft')]}"/>
 
48
                </div>
 
49
            """
 
50
            }
 
51
        for k,v in layouts.items():
 
52
            if fmt and (k in fmt):
 
53
                doc = etree.fromstring(arch)
 
54
                for node in doc.xpath(
 
55
                    "//div[@class='oe_subtotal_footer_separator']"):
 
56
                    tree = etree.fromstring(v)
 
57
                    node.getparent().replace(node, tree)
 
58
                arch = etree.tostring(doc)
 
59
                break
 
60
        return arch
 
61
    
 
62
    def fields_view_get(self, cr, uid, view_id=None, view_type=False,
 
63
        context=None, toolbar=False, submenu=False):
 
64
        res = super(account_voucher, self).fields_view_get(cr, uid,
 
65
            view_id=view_id, view_type=view_type, context=context,
 
66
            toolbar=toolbar, submenu=submenu)
 
67
        if view_type == 'form':
 
68
            res['arch'] = self.fields_view_get_address(cr, uid, res['arch'],
 
69
                context=context)
 
70
        return res
 
71
        
 
72
    def _check_conciled(self, cr, uid, ids, name, arg, context=None):
 
73
        res = {}
 
74
        for voucher in self.browse(cr, uid, ids, context=context):
 
75
            reconcile = False
 
76
            for line in voucher.move_ids:
 
77
                if line.reconcile_id or line.reconcile_partial_id:
 
78
                    reconcile = True
 
79
            if reconcile == False:
 
80
                res[voucher.id] = False
 
81
            else:
 
82
                res[voucher.id] = True
 
83
        return res
 
84
        
 
85
    def _voucher_search(self, cr, uid, obj, name, args, context=None):
 
86
        if not len(args):
 
87
            return []
 
88
        company_user = self.pool.get('res.users').browse(cr, uid, uid,
 
89
            context=context).company_id.id
 
90
        company_id = self.pool.get('res.company').browse(cr, uid, company_user,
 
91
            context=context).id
 
92
        list_voucher = []
 
93
        for voucher in self.search(cr, uid, [('state','=','posted'), (
 
94
            'company_id', '=', company_id)]):
 
95
            reconcile = False
 
96
            for line in self.browse(cr, uid, voucher, context=context).move_ids:
 
97
                if line.reconcile_id.id or line.reconcile_partial_id.id:
 
98
                    reconcile = True
 
99
                    break
 
100
                else:
 
101
                    reconcile = False
 
102
            if reconcile == False:
 
103
                list_voucher.append(voucher)
 
104
        return [('id', 'in', [x for x in list_voucher])]
 
105
        
 
106
    _columns = {
 
107
        'conciled' : fields.function(_check_conciled, type='boolean',
 
108
            string='References', method=True, fnct_search=_voucher_search)
 
109
        }