[MERGE] Merged Valencia's branch for the fix of variable declaration inside mrp_repai...
authorJay Vora (OpenERP) <jvo@tinyerp.com>
Fri, 19 Aug 2011 06:55:31 +0000 (12:25 +0530)
committerJay Vora (OpenERP) <jvo@tinyerp.com>
Fri, 19 Aug 2011 06:55:31 +0000 (12:25 +0530)
bzr revid: jvo@tinyerp.com-20110819065531-c0vv9qawn9k5dang

addons/account/report/partner_balance.py
addons/account/report/third_party_ledger.py
addons/mrp/mrp.py
addons/mrp_repair/mrp_repair.py
addons/point_of_sale/pos.py
bin/addons/base/res/partner/partner.py
bin/addons/base/res/partner/partner_view.xml
bin/report/custom.py
bin/tools/safe_eval.py

index 6540086..f6d1e46 100755 (executable)
@@ -196,7 +196,7 @@ class partner_balance(report_sxw.rml_parse):
         result_tmp = 0.0
         if self.date_lst:
             self.cr.execute(
-                "SELECT p.ref,l.account_id,ac.name as account_name,ac.code as code ,p.name, sum(debit) as debit, sum(credit) as credit, " \
+                "SELECT p.ref,l.account_id,ac.name as account_name,ac.code as code ,p.name, COALESCE(sum(debit),0.00) as debit, COALESCE(sum(credit),0.00) as credit, " \
                         "CASE WHEN sum(debit) > sum(credit) " \
                             "THEN sum(debit) - sum(credit) " \
                             "ELSE 0 " \
index def13b4..c878ecc 100644 (file)
@@ -255,7 +255,7 @@ class third_party_ledger(rml_parse.rml_parse):
 #                              full_account.append(r)
                if self.date_lst_string:
                        self.cr.execute(
-                               "SELECT l.id,l.date,j.code, l.ref, l.name, l.debit, l.credit " \
+                               "SELECT l.id,l.date,j.code, l.ref, l.name, COALESCE(l.debit,0.00) as debit, COALESCE(l.credit,0.00) as credit " \
                                "FROM account_move_line l " \
                                "LEFT JOIN account_journal j " \
                                        "ON (l.journal_id = j.id) " \
index dcbeba2..e0ce333 100644 (file)
@@ -815,8 +815,8 @@ class mrp_procurement(osv.osv):
                     phantom_bom_id = self.pool.get('mrp.bom').search(cr, uid, [
                         ('product_id', '=', procurement.move_id.product_id.id),
                         ('bom_id', '=', False),
-                        ('type', '=', 'phantom')]) 
-                    return phantom_bom_id 
+                        ('type', '=', 'phantom')])
+                    return phantom_bom_id
         return False
 
     def check_move_cancel(self, cr, uid, ids, context={}):
@@ -993,8 +993,12 @@ class mrp_procurement(osv.osv):
     def action_produce_assign_product(self, cr, uid, ids, context={}):
         produce_id = False
         company = self.pool.get('res.users').browse(cr, uid, uid, context).company_id
+        move_obj = self.pool.get('stock.move')
         for procurement in self.browse(cr, uid, ids):
-            res_id = procurement.move_id.id
+            res_id = procurement.move_id.id or False
+            if not res_id:
+                raise osv.except_osv(_('Warning !'), _('No reservation is defined for the selected procurement.'))
+            move_obj.write(cr, uid, [res_id],{'location_id':procurement.location_id.id})
             loc_id = procurement.location_id.id
             newdate = DateTime.strptime(procurement.date_planned, '%Y-%m-%d %H:%M:%S') - DateTime.RelativeDateTime(days=procurement.product_id.product_tmpl_id.produce_delay or 0.0)
             newdate = newdate - DateTime.RelativeDateTime(days=company.manufacturing_lead)
@@ -1011,20 +1015,19 @@ class mrp_procurement(osv.osv):
                 'date_planned': newdate.strftime('%Y-%m-%d %H:%M:%S'),
                 'move_prod_id': res_id,
             })
+
             self.write(cr, uid, [procurement.id], {'state':'running'})
             bom_result = self.pool.get('mrp.production').action_compute(cr, uid,
                     [produce_id], properties=[x.id for x in procurement.property_ids])
             wf_service = netsvc.LocalService("workflow")
             wf_service.trg_validate(uid, 'mrp.production', produce_id, 'button_confirm', cr)
-            self.pool.get('stock.move').write(cr, uid, [res_id],
-                    {'location_id':procurement.location_id.id})
         return produce_id
 
     def action_po_assign(self, cr, uid, ids, context={}):
         purchase_id = False
         company = self.pool.get('res.users').browse(cr, uid, uid, context).company_id
         for procurement in self.browse(cr, uid, ids):
-            res_id = procurement.move_id.id
+            res_id = procurement.move_id.id or False
             partner = procurement.product_id.seller_ids[0].name
             partner_id = partner.id
             address_id = self.pool.get('res.partner').address_get(cr, uid, [partner_id], ['delivery'])['delivery']
@@ -1035,7 +1038,7 @@ class mrp_procurement(osv.osv):
             qty = self.pool.get('product.uom')._compute_qty(cr, uid, procurement.product_uom.id, procurement.product_qty, uom_id)
             if procurement.product_id.seller_ids[0].qty:
                 qty=max(qty,procurement.product_id.seller_ids[0].qty)
-                
+
             price = self.pool.get('product.pricelist').price_get(cr, uid, [pricelist_id], procurement.product_id.id, qty, partner_id, {'uom': uom_id})[pricelist_id]
 
             newdate = DateTime.strptime(procurement.date_planned, '%Y-%m-%d %H:%M:%S')
@@ -1044,7 +1047,7 @@ class mrp_procurement(osv.osv):
 
             #Passing partner_id to context for purchase order line integrity of Line name
             context.update({'lang':partner.lang, 'partner_id':partner_id})
-            
+
             product=self.pool.get('product.product').browse(cr,uid,procurement.product_id.id,context=context)
 
             line = {
@@ -1161,11 +1164,11 @@ class stock_warehouse_orderpoint(osv.osv):
         'name': lambda x,y,z,c: x.pool.get('ir.sequence').get(y,z,'mrp.warehouse.orderpoint') or '',
         'product_uom': lambda sel, cr, uid, context: context.get('product_uom', False),
     }
-    
+
     _sql_constraints = [
         ( 'qty_multiple_check', 'CHECK( qty_multiple > 0 )', _('Qty Multiple must be greater than zero.')),
     ]
-    
+
     def onchange_warehouse_id(self, cr, uid, ids, warehouse_id, context={}):
         if warehouse_id:
             w=self.pool.get('stock.warehouse').browse(cr,uid,warehouse_id, context)
index 737922b..85360ad 100644 (file)
@@ -256,6 +256,9 @@ class mrp_repair(osv.osv):
         res={}
         invoices_group = {}
         inv_obj = self.pool.get('account.invoice')
+        invoice_line_obj = self.pool.get('account.invoice.line')
+        repair_fee_obj = self.pool.get('mrp.repair.fee')
+        repair_line_obj = self.pool.get('mrp.repair.line')
         for repair in self.browse(cr, uid, ids, context=context):
             res[repair.id]=False
             if repair.state in ('draft','cancel') or repair.invoice_id:
@@ -265,8 +268,8 @@ class mrp_repair(osv.osv):
             comment=repair.quotation_notes
             if (repair.invoice_method != 'none'):
                 if group and repair.partner_invoice_id.id in invoices_group:
-                    inv_id= invoices_group[repair.partner_invoice_id.id]
-                    invoice=inv_obj.browse(cr, uid,inv_id)
+                    inv_id = invoices_group[repair.partner_invoice_id.id]
+                    invoice = inv_obj.browse(cr, uid,inv_id)
                     invoice_vals = {
                         'name': invoice.name +', '+repair.name,
                         'origin': invoice.origin+', '+repair.name,
@@ -306,7 +309,7 @@ class mrp_repair(osv.osv):
                         else:
                             raise osv.except_osv(_('Error !'), _('No account defined for product "%s".') % operation.product_id.name )
 
-                        invoice_line_id = self.pool.get('account.invoice.line').create(cr, uid, {
+                        invoice_line_id = invoice_line_obj.create(cr, uid, {
                             'invoice_id': inv_id,
                             'name': name,
                             'origin':repair.name,
@@ -318,7 +321,7 @@ class mrp_repair(osv.osv):
                             'price_subtotal' : operation.product_uom_qty*operation.price_unit,
                             'product_id' : operation.product_id and operation.product_id.id or False
                             })
-                        self.pool.get('mrp.repair.line').write(cr, uid, [operation.id], {'invoiced':True,'invoice_line_id':invoice_line_id})
+                        repair_line_obj.write(cr, uid, [operation.id], {'invoiced':True,'invoice_line_id':invoice_line_id})
                 for fee in repair.fees_lines:
                     if fee.to_invoice == True:
                         if group:
@@ -333,7 +336,7 @@ class mrp_repair(osv.osv):
                             account_id = fee.product_id.categ_id.property_account_income_categ.id
                         else:
                             raise osv.except_osv(_('Error !'), _('No account defined for product "%s".') % fee.product_id.name)
-                        invoice_fee_id = self.pool.get('account.invoice.line').create(cr, uid, {
+                        invoice_fee_id = invoice_line_obj.create(cr, uid, {
                             'invoice_id': inv_id,
                             'name': name,
                             'origin':repair.name,
@@ -345,7 +348,7 @@ class mrp_repair(osv.osv):
                             'price_unit': fee.price_unit,
                             'price_subtotal': fee.product_uom_qty*fee.price_unit
                             })
-                        self.pool.get('mrp.repair.fee').write(cr, uid, [fee.id], {'invoiced':True,'invoice_line_id':invoice_fee_id})
+                        repair_fee_obj.write(cr, uid, [fee.id], {'invoiced':True,'invoice_line_id':invoice_fee_id})
                 res[repair.id]=inv_id
         #self.action_invoice_end(cr, uid, ids)
         return res
index 8b3d91a..27f1cb7 100644 (file)
@@ -303,6 +303,7 @@ class pos_order(osv.osv):
         """Create a picking for each order and validate it."""
         picking_obj = self.pool.get('stock.picking')
         partner_obj = self.pool.get('res.partner')
+        move_obj = self.pool.get('stock.move')
         address_id = False
         orders = self.browse(cr, uid, ids, context)
         for order in orders:
@@ -348,8 +349,8 @@ class pos_order(osv.osv):
                         if line.qty < 0:
                             (location_id, stock_dest_id)= (stock_dest_id, location_id)
 
-                        self.pool.get('stock.move').create(cr, uid, {
-                            'name': 'Stock move (POS %d)' % (order.id, ),
+                        move_obj.create(cr, uid, {
+                            'name': 'Stock move (%s) ' % (order.name, ) + line.product_id.partner_ref,
                             'product_uom': line.product_id.uom_id.id,
                             'product_uos': line.product_id.uom_id.id,
                             'picking_id': picking_id,
index 5bf33cc..4ed7db4 100644 (file)
@@ -217,8 +217,10 @@ class res_partner(osv.osv):
         return True
 
     def address_get(self, cr, uid, ids, adr_pref=['default']):
-        cr.execute('select type,id from res_partner_address where partner_id in %s', (tuple(ids),))
-        res = cr.fetchall()
+        address_obj = self.pool.get('res.partner.address')
+        address_ids = address_obj.search(cr, uid, [('partner_id', '=', ids)])
+        address_rec = address_obj.read(cr, uid, address_ids, ['type'])
+        res = list(tuple(addr.values()) for addr in address_rec)
         adr = dict(res)
         # get the id of the (first) default address if there is one,
         # otherwise get the id of the first address in the list
index 6ed8118..dea6977 100644 (file)
@@ -95,6 +95,7 @@
                     <newline/>
                     <field name="mobile" select="2"/>
                     <field name="email" select="2" widget="email"/>
+                    <field name="active" select="2"/>
                 </form>
             </field>
         </record>
index ec4ea28..48fc88e 100644 (file)
@@ -505,6 +505,7 @@ class report_custom(report_int):
         colors = map(lambda x:fill_style.Plain(bgcolor=x), misc.choice_colors(nb_bar))
         
         abscissa = {}
+        idx0 = 0
         for line in data_by_year.keys():
             fields_bar = []
             # sum data and save it in a list. An item for a fields
@@ -532,7 +533,6 @@ class report_custom(report_int):
                     if fields[idx+1]['cumulate']:
                         prev += data[k]
                         
-                idx0 = 0
                 plot = bar_plot.T(label=fields[idx+1]['name']+' '+str(line), data = data_cum, cluster=(idx0*(len(fields)-1)+idx,nb_bar), fill_style=colors[idx0*(len(fields)-1)+idx])
                 ar.add_plot(plot)
                 abscissa.update(fields_bar[idx])
index 665b534..69cd69f 100644 (file)
@@ -54,9 +54,12 @@ _EXPR_OPCODES = _CONST_OPCODES.union(set(opmap[x] for x in [
 
 _SAFE_OPCODES = _EXPR_OPCODES.union(set(opmap[x] for x in [
     'STORE_MAP', 'LOAD_NAME', 'CALL_FUNCTION', 'COMPARE_OP', 'LOAD_ATTR',
-    'STORE_NAME', 'GET_ITER', 'FOR_ITER', 'LIST_APPEND', 'JUMP_ABSOLUTE',
-    'DELETE_NAME', 'JUMP_IF_TRUE', 'JUMP_IF_FALSE','MAKE_FUNCTION','JUMP_FORWARD',
-    'SLICE+0', 'SLICE+1', 'SLICE+2', 'SLICE+3'
+    'STORE_NAME', 'GET_ITER', 'FOR_ITER', 'LIST_APPEND', 'DELETE_NAME',
+    'JUMP_FORWARD', 'JUMP_IF_TRUE', 'JUMP_IF_FALSE', 'JUMP_ABSOLUTE',
+    'MAKE_FUNCTION', 'SLICE+0', 'SLICE+1', 'SLICE+2', 'SLICE+3',
+    # New in Python 2.7 - http://bugs.python.org/issue4715 :
+    'JUMP_IF_FALSE_OR_POP', 'JUMP_IF_TRUE_OR_POP', 'POP_JUMP_IF_FALSE',
+    'POP_JUMP_IF_TRUE'
     ] if x in opmap))
 
 _logger = logging.getLogger('safe_eval')