~vauxoo/addons-vauxoo/rico_contract_fix_email_and_more_dev_ernesto

« back to all changes in this revision

Viewing changes to account_analytic_analysis_rent/account_analytic_account_rent.py

  • Committer: Rodo
  • Date: 2013-08-02 22:27:05 UTC
  • Revision ID: rodo@vauxoo.com-20130802222705-1pgk8quq4km89apk
[IMP][account_analytic_account_rent] add counter in feature, add warning in product-prodlot

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
class account_analytic_product(osv.osv):
37
37
    _name='account.analytic.product'
38
38
    
39
 
    
 
39
 
 
40
    def onchange_prodlot(self, cr , uid, ids, prodlot_id, context=None):
 
41
        if context==None:
 
42
            context={}
 
43
        res={}
 
44
        if prodlot_id:
 
45
            prodlot_obj=self.pool.get('stock.production.lot')
 
46
            if prodlot_obj.browse(cr, uid, prodlot_id, context=context).stock_available < 0:
 
47
                res={'value':{'prodlot_id': False },'warning':{
 
48
                'title': _('This product is already rented  !'),
 
49
                'message': _('This product is already rented,check serial number.')
 
50
            }}
 
51
        return res
 
52
        
40
53
    def onchange_product_id(self, cr, uid, ids, product_id, context=None):
41
54
        res={}
42
55
        list=[]
61
74
 
62
75
class account_analytic_line(osv.osv):
63
76
    _inherit='account.analytic.line'
 
77
    _order='product_id'
64
78
    
65
79
    def _check_inv(self, cr, uid, ids, vals):
66
80
        select = ids
82
96
    _columns={
83
97
        'w_start': fields.integer('Inicial'),
84
98
        'w_end': fields.integer('Final'),
 
99
        'feature_id': fields.many2one('product.feature.line','Feature')
85
100
    }
86
101
 
87
102
 
108
123
            for prod in product_ids:
109
124
                if prod[2]['product_id']:
110
125
                    for feature in product_obj.browse(cr, uid, prod[2]['product_id'], context=context).feature_ids:
111
 
                        if {'name':feature.name.id} not in list_feature:
112
 
                            list_feature.append({'name':feature.name.id})
 
126
                        list_feature.append({'name':feature.name.id, 'product_line_id':prod[2]['product_id'],'counter':feature.counter})
113
127
        return {'value':{'feature_ids': [(0, 6, data) for data in list_feature]}}
114
128
 
115
129
    def _get_journal(self, cr, uid, context=None):
167
181
        product_obj=self.pool.get('product.product')
168
182
        ware_id=warehouse_obj.search(cr, uid, [], context=context)[0]
169
183
        warehouse=warehouse_obj.browse(cr ,uid, ware_id, context=context)
 
184
        location = self.pool.get('stock.location').search(cr, uid, [('usage', '=', 'customer')], context=context)
 
185
        if location:
 
186
            location=location[0]
 
187
        else:
 
188
            raise osv.except_osv(_('Error!'),  _('You not have a configured client location'))
170
189
        for contract in self.browse(cr, uid , ids , context=context):
171
190
            picking_id=picking_obj.create(cr, uid, {'origin':contract.name, 'address_id':contract.contact_id.id,'date':contract.date_start,'type':'in'}, context=context)
172
191
            for prod in contract.product_ids:
173
 
                move_obj.create(cr, uid, {'name':prod.product_id.name,'product_id':prod.product_id.id,'product_qty':1,'picking_id':picking_id,'product_uom':prod.product_id.uom_id.id,'location_id':warehouse.lot_output_id.id,'location_dest_id':warehouse.lot_input_id.id, 'prodlot_id':prod.prodlot_id.id}, context=context)
 
192
                move_obj.create(cr, uid, {'name':prod.product_id.name,'product_id':prod.product_id.id,'product_qty':1,'picking_id':picking_id,'product_uom':prod.product_id.uom_id.id,'location_id':location,'location_dest_id':warehouse.lot_input_id.id, 'prodlot_id':prod.prodlot_id.id}, context=context)
174
193
                product_obj.write(cr, uid, prod.product_id.id, {'rent':False, 'contract_id': False}, context=context)
175
194
        return super(account_analytic_account, self).set_close(cr, uid, ids, context=context)
176
195
    
195
214
                    if not a:
196
215
                        a = prod.product_id.categ_id.property_account_income_categ.id
197
216
                    for feature in contract.feature_ids:
198
 
                        line_obj.create(cr, uid, {'date':date_invoice,'name':feature.name.name,'product_id':prod.product_id.id,'product_uom_id':prod.product_id.uom_id.id,'general_account_id':a,'to_invoice':1,'account_id':contract.id,'journal_id':contract.journal_id.analytic_journal_id.id,'amount':feature.cost},context=context)
 
217
                        if feature.product_line_id.id==prod.product_id.id:
 
218
                            line_obj.create(cr, uid, {'date':date_invoice,'name':feature.name.name,'product_id':prod.product_id.id,'product_uom_id':prod.product_id.uom_id.id,'general_account_id':a,'to_invoice':1,'account_id':contract.id,'journal_id':contract.journal_id.analytic_journal_id.id,'amount':feature.cost, 'feature_id':feature.id},context=context)
199
219
                    product_obj.write(cr, uid, prod.product_id.id, {'rent':True,'contract_id':contract.id}, context=context)
200
220
                date_invoice=(datetime.strptime(date_invoice, "%Y-%m-%d") + relativedelta(months=1)).strftime("%Y-%m-%d")
201
221
        return super(account_analytic_account, self).set_open(cr, uid, ids, context=context)