~savoirfairelinux-openerp/sale-wkfl/sale_lot_tracking

« back to all changes in this revision

Viewing changes to sale_line_description/sale.py

  • Committer: Joel Grand-Guillaume
  • Author(s): Alex Comba
  • Date: 2013-11-15 15:26:51 UTC
  • mfrom: (19.3.7 adding_sale_line_description_7)
  • Revision ID: joel.grandguillaume@camptocamp.com-20131115152651-g1vokg105spgn3fo
[MRG] [ADD] module sale_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 sale_order_line(orm.Model):
 
26
    _inherit = "sale.order.line"
 
27
 
 
28
    def product_id_change(
 
29
        self, cr, uid, ids, pricelist, product_id, qty=0,
 
30
        uom=False, qty_uos=0, uos=False, name='', partner_id=False,
 
31
        lang=False, update_tax=True, date_order=False, packaging=False,
 
32
        fiscal_position=False, flag=False, context=None
 
33
    ):
 
34
        res = super(sale_order_line, self).product_id_change(
 
35
            cr, uid, ids, pricelist, product_id, qty=qty, uom=uom,
 
36
            qty_uos=qty_uos, uos=uos, name='', partner_id=partner_id,
 
37
            lang=lang, update_tax=update_tax, date_order=date_order,
 
38
            packaging=packaging, fiscal_position=fiscal_position,
 
39
            flag=flag, context=context
 
40
        )
 
41
        if product_id:
 
42
            user = self.pool.get('res.users').browse(
 
43
                cr, uid, uid, context=context)
 
44
            user_groups = [g.id for g in user.groups_id]
 
45
            ref = self.pool.get('ir.model.data').get_object_reference(
 
46
                cr, uid, 'sale_line_description',
 
47
                'group_use_product_description_per_so_line'
 
48
            )
 
49
            if ref and len(ref) > 1 and ref[1]:
 
50
                group_id = ref[1]
 
51
                if group_id in user_groups:
 
52
                    product_obj = self.pool.get('product.product')
 
53
                    product = product_obj.browse(
 
54
                        cr, uid, product_id, context=context)
 
55
                    if (
 
56
                        product
 
57
                        and product.description
 
58
                        and 'value' in res
 
59
                    ):
 
60
                        res['value']['name'] = product.description
 
61
        return res