~camptocamp/account-invoicing/correct_payment_term_balance_mdh

« back to all changes in this revision

Viewing changes to invoice_line_description/invoice.py

  • Committer: Alex Comba
  • Date: 2014-01-20 14:15:36 UTC
  • mto: This revision was merged to the branch mainline in revision 39.
  • Revision ID: alex.comba@agilebg.com-20140120141536-rxdx1pe83wgf3jn4
[ADD] module invoice_line_description

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
##############################################################################
 
3
#
 
4
#    Copyright (C) 2013 Agile Business Group sagl
 
5
#    (<http://www.agilebg.com>)
 
6
#
 
7
#    This program is free software: you can redistribute it and/or modify
 
8
#    it under the terms of the GNU Affero General Public License as published
 
9
#    by the Free Software Foundation, either version 3 of the License, or
 
10
#    (at your option) any later version.
 
11
#
 
12
#    This program is distributed in the hope that it will be useful,
 
13
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
#    GNU Affero General Public License for more details.
 
16
#
 
17
#    You should have received a copy of the GNU Affero General Public License
 
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
##############################################################################
 
21
 
 
22
from openerp.osv import orm
 
23
 
 
24
 
 
25
class account_invoice_line(orm.Model):
 
26
    _inherit = "account.invoice.line"
 
27
 
 
28
    def product_id_change(
 
29
        self, cr, uid, ids, product_id, uom_id, qty=0,
 
30
        name='', type='out_invoice', partner_id=False, fposition_id=False,
 
31
        price_unit=False, currency_id=False, context=None, company_id=None
 
32
    ):
 
33
        res = super(account_invoice_line, self).product_id_change(
 
34
            cr, uid, ids, product_id, uom_id, qty=qty,
 
35
            name=name, type=type, partner_id=partner_id,
 
36
            fposition_id=fposition_id, price_unit=price_unit,
 
37
            currency_id=currency_id, context=context, company_id=company_id
 
38
        )
 
39
        if product_id:
 
40
            user = self.pool.get('res.users').browse(
 
41
                cr, uid, uid, context=context)
 
42
            user_groups = [g.id for g in user.groups_id]
 
43
            ref = self.pool.get('ir.model.data').get_object_reference(
 
44
                cr, uid, 'invoice_line_description',
 
45
                'group_use_product_description_per_inv_line'
 
46
            )
 
47
            if ref and len(ref) > 1 and ref[1]:
 
48
                group_id = ref[1]
 
49
                if group_id in user_groups:
 
50
                    product_obj = self.pool.get('product.product')
 
51
                    product = product_obj.browse(
 
52
                        cr, uid, product_id, context=context)
 
53
                    if (
 
54
                        product
 
55
                        and product.description
 
56
                        and 'value' in res
 
57
                    ):
 
58
                        res['value']['name'] = product.description
 
59
        return res