Reviewers: ,


Please review this at http://codereview.tryton.org/360001/

Affected files:
  M sale.py
  M sale.xml


Index: sale.py
===================================================================
--- a/sale.py
+++ b/sale.py
@@ -181,16 +181,16 @@
                 ('draft', 'cancel'),
                 ('quotation', 'cancel'),
                 ('quotation', 'draft'),
+                ('cancel', 'draft'),
                 ))
         self._buttons.update({
                 'cancel': {
-                    'invisible': ((Eval('state') == 'cancel')
-                        | (~Eval('state').in_(['draft', 'quotation'])
-                            & (Eval('invoice_state') != 'exception')
-                            & (Eval('shipment_state') != 'exception'))),
+ 'invisible': ~Eval('state').in_(['draft', 'quotation']),
                     },
                 'draft': {
-                    'invisible': Eval('state') != 'quotation',
+ 'invisible': ~Eval('state').in_(['cancel', 'quotation']),
+                    'icon': If(Eval('state') == 'cancel', 'tryton-clear',
+                        'tryton-go-previous'),
                     },
                 'quote': {
                     'invisible': Eval('state') != 'draft',
@@ -738,6 +738,9 @@
         invoice_line_obj = pool.get('account.invoice.line')
         sale_line_obj = pool.get('sale.line')

+        if sale.invoice_method == 'manual':
+            return
+
         if not sale.party.account_receivable:
             self.raise_user_error('missing_account_receivable',
                     error_args=(sale.party.rec_name,))
@@ -812,6 +815,9 @@
         move_obj = pool.get('stock.move')
         sale_line_obj = pool.get('sale.line')

+        if sale.shipment_method == 'manual':
+            return
+
         moves = self._get_move_sale_line(sale, shipment_type)
         if not moves:
             return
@@ -849,7 +855,10 @@
         return shipments

     def is_done(self, sale):
- return sale.invoice_state == 'paid' and sale.shipment_state == 'sent'
+        return ((sale.invoice_state == 'paid'
+                or sale.invoice_method == 'manual')
+            and (sale.shipment_state == 'sent'
+                or sale.shipment_method == 'manual'))

     def delete(self, ids):
         if isinstance(ids, (int, long)):
@@ -1429,8 +1438,17 @@
             return
         if (shipment_type == 'out') != (line.quantity >= 0):
             return
+
+        if line.sale.shipment_method == 'order':
+            quantity = abs(line.quantity)
+        else:
+            quantity = 0.0
+            for invoice_line in line.invoice_lines:
+                if invoice_line.invoice.state in ('open', 'paid'):
+                    quantity += uom_obj.compute_qty(invoice_line.unit,
+                        invoice_line.quantity, line.unit)
+
         skip_ids = set(x.id for x in line.moves_recreated)
-        quantity = abs(line.quantity)
         for move in line.moves:
             if move.id not in skip_ids:
                 quantity -= uom_obj.compute_qty(move.uom, move.quantity,
Index: sale.xml
===================================================================
--- a/sale.xml
+++ b/sale.xml
@@ -91,8 +91,7 @@
                                 <group col="7" colspan="2" id="buttons">
<button name="cancel" type="object" string="Cancel"
                                         icon="tryton-cancel"/>
- <button name="draft" type="object" string="Draft"
-                                        icon="tryton-go-previous"/>
+ <button name="draft" type="object" string="Draft"/> <button name="quote" type="object" string="Quote"
                                         icon="tryton-go-next"/>
<button name="%(wizard_invoice_handle_exception)d"


--
[email protected] mailing list

Reply via email to