[MERGE] Cancelling sale order should affect Procurements,production orders
authorRaphael Collet <rco@openerp.com>
Wed, 14 Sep 2011 14:17:35 +0000 (16:17 +0200)
committerRaphael Collet <rco@openerp.com>
Wed, 14 Sep 2011 14:17:35 +0000 (16:17 +0200)
bzr revid: rco@openerp.com-20110914141735-xysq4cvyagges1uc

addons/account/account.py
addons/account/account_move_line.py
addons/account/invoice.py
addons/sale/sale.py
bin/report/render/rml2pdf/trml2pdf.py
bin/tools/safe_eval.py

index 5782e12..6359906 100644 (file)
@@ -1246,11 +1246,13 @@ class account_move_reconcile(osv.osv):
         'name': lambda self,cr,uid,ctx={}: self.pool.get('ir.sequence').get(cr, uid, 'account.reconcile') or '/',
     }
     def reconcile_partial_check(self, cr, uid, ids, type='auto', context={}):
-        total = 0.0 
+        total = 0.0
+        currency_rec = False
         for rec in self.browse(cr, uid, ids, context):
             for line in rec.line_partial_ids:
+                currency_rec = line.account_id.company_id.currency_id
                 total += (line.debit or 0.0) - (line.credit or 0.0)
-        if not total:
+        if currency_rec and self.pool.get('res.currency').is_zero(cr, uid, currency_rec, total):
             self.pool.get('account.move.line').write(cr, uid,
                 map(lambda x: x.id, rec.line_partial_ids),
                 {'reconcile_id': rec.id }
index 9bcd71e..7cd9667 100644 (file)
@@ -517,7 +517,9 @@ class account_move_line(osv.osv):
         unmerge = []
         total = 0.0
         merges_rec = []
+        currency_rec = False
         for line in self.browse(cr, uid, ids, context):
+            currency_rec = line.account_id.company_id.currency_id
             if line.reconcile_id:
                 raise osv.except_osv(_('Already Reconciled'), _('Already Reconciled'))
             if line.reconcile_partial_id:
@@ -530,8 +532,7 @@ class account_move_line(osv.osv):
             else:
                 unmerge.append(line.id)
                 total += (line.debit or 0.0) - (line.credit or 0.0)
-
-        if not total:
+        if currency_rec and self.pool.get('res.currency').is_zero(cr, uid, currency_rec, total):
             res = self.reconcile(cr, uid, merges+unmerge, context=context)
             return res
         r_id = self.pool.get('account.move.reconcile').create(cr, uid, {
index 1d4b1f7..696e75d 100644 (file)
@@ -113,8 +113,8 @@ class account_invoice(osv.osv):
                 continue
             inv_total = inv.amount_total
             context_unreconciled = context.copy()
-            for lines in inv.move_lines:
-                if lines.currency_id and lines.currency_id.id == inv.currency_id.id:
+            for lines in inv.payment_ids:
+                if lines.amount_currency and lines.currency_id.id == inv.currency_id.id:
                    if inv.type in ('out_invoice','in_refund'):
                         inv_total += lines.amount_currency
                    else:
@@ -128,6 +128,8 @@ class account_invoice(osv.osv):
             res[inv.id] =  self.pool.get('res.currency').round(cr, uid, inv.currency_id, result)
         return res
 
+    #This function is called by the fields.function move_lines, which is probably unused now.
+    #This function is also wrongly computed: you should use the one on the field payment_ids instead
     def _get_lines(self, cr, uid, ids, name, arg, context=None):
         res = {}
         for id in ids:
@@ -285,6 +287,7 @@ class account_invoice(osv.osv):
             }, help="The account moves of the invoice have been reconciled with account moves of the payment(s)."),
         'partner_bank': fields.many2one('res.partner.bank', 'Bank Account',
             help='The bank account to pay to or to be paid from'),
+        #this field is probably unused, and wrongly computed. Use payment_ids instead.
         'move_lines':fields.function(_get_lines , method=True,type='many2many' , relation='account.move.line',string='Move Lines'),
         'residual': fields.function(_amount_residual, method=True, digits=(16, int(config['price_accuracy'])),string='Residual',
             store={
index 7ff7482..fea92c8 100644 (file)
@@ -517,7 +517,6 @@ class sale_order(osv.osv):
                                 wf_service.trg_validate(uid, 'mrp.procurement', proc, 'button_check', cr)
             for r in self.read(cr, uid, ids, ['picking_ids']):
                 for pick in r['picking_ids']:
-                    wf_service = netsvc.LocalService("workflow")
                     wf_service.trg_validate(uid, 'stock.picking', pick, 'button_cancel', cr)
             for inv in sale.invoice_ids:
                 if inv.state not in ('draft', 'cancel'):
@@ -526,7 +525,6 @@ class sale_order(osv.osv):
                         _('You must first cancel all invoices attached to this sale order.'))
             for r in self.read(cr, uid, ids, ['invoice_ids']):
                 for inv in r['invoice_ids']:
-                    wf_service = netsvc.LocalService("workflow")
                     wf_service.trg_validate(uid, 'account.invoice', inv, 'invoice_cancel', cr)
             sale_order_line_obj.write(cr, uid, [l.id for l in  sale.order_line],
                     {'state': 'cancel'})
index 9171285..72bee75 100644 (file)
@@ -485,9 +485,11 @@ class _rml_flowable(object):
             paraStyle = None
             if tr.get('style'):
                 st = copy.deepcopy(self.styles.table_styles[tr.get('style')])
-                for s in st._cmds:
-                    s[1][1] = posy
-                    s[2][1] = posy
+                for si in range(len(st._cmds)):
+                    s = list(st._cmds[si])
+                    s[1] = (s[1][0],posy)
+                    s[2] = (s[2][0],posy)
+                    st._cmds[si] = tuple(s)
                 styles.append(st)
             if tr.get('paraStyle'):
                 paraStyle = self.styles.styles[tr.get('paraStyle')]
index 69cd69f..cb6da41 100644 (file)
@@ -264,6 +264,8 @@ def safe_eval(expr, globals_dict=None, locals_dict=None, mode="eval", nocopy=Fal
                 'list': list,
                 'tuple': tuple,
                 'map': map,
+                'max': max,
+                'min': min,
                 'abs': abs,
                 'reduce': reduce,
                 'filter': filter,