~vauxoo/addons-vauxoo/8.0-import_tax_tariff-dev-yani-rev-2

« back to all changes in this revision

Viewing changes to purchase_requisition_make_po/purchase_requisition.py

  • Committer: jose at vauxoo
  • Date: 2013-07-25 20:54:29 UTC
  • mfrom: (543.7.110 vaddons-70)
  • 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
1
# -*- encoding: utf-8 -*-
2
 
##############################################################################
 
2
########################################################################
3
3
#
4
4
#    OpenERP, Open Source Management Solution
5
5
#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>). All Rights Reserved
18
18
#    You should have received a copy of the GNU Affero General Public License
19
19
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20
20
#
21
 
##############################################################################
 
21
########################################################################
22
22
from datetime import datetime
23
23
from dateutil.relativedelta import relativedelta
24
24
import time
25
25
from openerp import netsvc
26
26
 
27
 
from openerp.osv import fields,osv
 
27
from openerp.osv import fields, osv
28
28
from openerp.tools.translate import _
29
29
import openerp.addons.decimal_precision as dp
30
30
 
 
31
 
31
32
class purchase_requisition_line(osv.Model):
32
33
    _inherit = "purchase.requisition.line"
33
34
 
34
35
    _columns = {
35
36
        'name': fields.text('Description', required=True),
36
 
        'account_analytic_id': fields.many2one('account.analytic.account', 'Analytic Account', help='This field is used to assign the selected analytic account to the line of the purchase order'),
 
37
        'account_analytic_id': fields.many2one(
 
38
            'account.analytic.account', 'Analytic Account',
 
39
                help='This field is used to assign the selected'\
 
40
                ' analytic account to the line of the purchase order'),
37
41
    }
38
42
 
39
 
    def onchange_product_id(self, cr, uid, ids, product_id, \
40
 
               product_uom_id, context=None):
 
43
    def onchange_product_id(self, cr, uid, ids, product_id,
 
44
                            product_uom_id, context=None):
41
45
        product_obj = self.pool.get('product.product')
42
46
        res = {'value': {'name': ''}}
43
47
        if product_id:
44
 
            product_name = product_obj.name_get(cr, uid, product_id, context=context)
45
 
            dummy, name = product_name and product_name[0] or (False, False)
46
 
            
47
 
            product = product_obj.browse(cr, uid, product_id, context=context)
 
48
            product_name = product_obj.name_get(
 
49
                cr, uid, product_id, context=context)
 
50
            dummy, name = product_name and product_name[0] or (False,
 
51
                                                                False)
 
52
 
 
53
            product = product_obj.browse(cr, uid, product_id,
 
54
                                                    context=context)
48
55
            if product.description_purchase:
49
56
                name += '\n' + product.description_purchase
50
57
            res['value'].update({'name': name})
55
62
 
56
63
class purchase_requisition(osv.Model):
57
64
    _inherit = "purchase.requisition"
58
 
    
59
 
    def make_purchase_order(self, cr, uid, ids, partner_id, context=None):#method override
 
65
 
 
66
    def make_purchase_order(self, cr, uid, ids, partner_id,
 
67
                                    context=None):  # method override
60
68
        """
61
69
        Create New RFQ for Supplier
62
70
        """
67
75
        purchase_order_line = self.pool.get('purchase.order.line')
68
76
        res_partner = self.pool.get('res.partner')
69
77
        fiscal_position = self.pool.get('account.fiscal.position')
70
 
        supplier = res_partner.browse(cr, uid, partner_id, context=context)
71
 
        supplier_pricelist = supplier.property_product_pricelist_purchase or False
 
78
        supplier = res_partner.browse(cr, uid, partner_id,
 
79
                                                        context=context)
 
80
        supplier_pricelist =\
 
81
                supplier.property_product_pricelist_purchase or False
72
82
        res = {}
73
83
        for requisition in self.browse(cr, uid, ids, context=context):
74
 
            if supplier.id in filter(lambda x: x, [rfq.state <> 'cancel' and rfq.partner_id.id or None for rfq in requisition.purchase_ids]):
75
 
                 raise osv.except_osv(_('Warning!'), _('You have already one %s purchase order for this partner, you must cancel this purchase order to create a new quotation.') % rfq.state)
 
84
            if supplier.id in filter(lambda x: x,
 
85
                [rfq.state <> 'cancel' and rfq.partner_id.id or None\
 
86
                    for rfq in requisition.purchase_ids]):
 
87
                raise osv.except_osv(
 
88
                    _('Warning!'), _('You have already one %s purchase'\
 
89
                    ' order for this partner, you must cancel this'\
 
90
                    ' purchase order to create a new quotation.') %\
 
91
                                                              rfq.state)
76
92
            location_id = requisition.warehouse_id.lot_input_id.id
77
93
            purchase_id = purchase_order.create(cr, uid, {
78
 
                        'origin': requisition.name,
79
 
                        'partner_id': supplier.id,
80
 
                        'pricelist_id': supplier_pricelist.id,
81
 
                        'location_id': location_id,
82
 
                        'company_id': requisition.company_id.id,
83
 
                        'fiscal_position': supplier.property_account_position and supplier.property_account_position.id or False,
84
 
                        'requisition_id':requisition.id,
85
 
                        'notes':requisition.description,
86
 
                        'warehouse_id':requisition.warehouse_id.id ,
 
94
                'origin': requisition.name,
 
95
                'partner_id': supplier.id,
 
96
                'pricelist_id': supplier_pricelist.id,
 
97
                'location_id': location_id,
 
98
                'company_id': requisition.company_id.id,
 
99
                'fiscal_position': supplier.property_account_position\
 
100
                    and supplier.property_account_position.id or False,
 
101
                'requisition_id': requisition.id,
 
102
                'notes': requisition.description,
 
103
                'warehouse_id': requisition.warehouse_id.id,
87
104
            })
88
105
            res[requisition.id] = purchase_id
89
106
            for line in requisition.line_ids:
90
107
                product = line.product_id
91
 
                seller_price, qty, default_uom_po_id, date_planned = self._seller_details(cr, uid, line, supplier, context=context)
 
108
                seller_price, qty, default_uom_po_id, date_planned =\
 
109
                    self._seller_details(cr, uid, line, supplier,
 
110
                                                        context=context)
92
111
                taxes_ids = product.supplier_taxes_id
93
 
                taxes = fiscal_position.map_tax(cr, uid, supplier.property_account_position, taxes_ids)
 
112
                taxes = fiscal_position.map_tax(
 
113
                    cr, uid, supplier.property_account_position,
 
114
                                                            taxes_ids)
94
115
                purchase_order_line.create(cr, uid, {
95
116
                    'order_id': purchase_id,
96
 
                    #start custom change
 
117
                    # start custom change
97
118
                    #'name': product.partner_ref,
98
119
                    'name': line.name,
99
 
                    #end custom change
 
120
                    # end custom change
100
121
                    'product_qty': qty,
101
122
                    'product_id': product.id,
102
123
                    'product_uom': default_uom_po_id,
103
124
                    'price_unit': seller_price,
104
125
                    'date_planned': date_planned,
105
126
                    'taxes_id': [(6, 0, taxes)],
106
 
                    'account_analytic_id': line.account_analytic_id and line.account_analytic_id.id or False,
 
127
                    'account_analytic_id': line.account_analytic_id\
 
128
                            and line.account_analytic_id.id or False,
107
129
                }, context=context)
108
 
                
 
130
        if res:
 
131
            requisition_user = self.browse(
 
132
                cr, uid, res.keys()[0], context=context).user_id
 
133
            purchase_order_obj = self.pool.get('purchase.order')
 
134
            purchase_order_obj.write(
 
135
                            cr, uid, res[res.keys()[0]],
 
136
                            {'rfq_user_id': requisition_user.id})
109
137
        return res
 
138
 
 
139
 
 
140
class purchase_order(osv.Model):
 
141
    _inherit = "purchase.order"
 
142
 
 
143
    _columns = {
 
144
        'rfq_user_id': fields.many2one('res.users', 'Requisitor'),
 
145
    }