Browse Source

[ADD] create voucher payment and move lines

Gogs 7 years ago
parent
commit
568b55415e
1 changed files with 29 additions and 3 deletions
  1. 29 3
      models/account_voucher.py

+ 29 - 3
models/account_voucher.py

@@ -29,7 +29,7 @@ class AccountVoucher(models.Model):
             'picking_policy': 'direct',
             'state': 'manual',
             'date_confirm': date_now,
-            'payment_term': 5
+            'payment_term': 4
         }
 
         sale_order = self.env['sale.order'].create(sale_order_values)
@@ -88,7 +88,7 @@ class AccountVoucher(models.Model):
                     'name': '/',
                     'price': current_price if total_line[1] else total - amount_paid,
                     'account_id': invoice.account_id.id,
-                    'date_maturity': invoice.date_due,            
+                    'date_maturity': total_line[0],            
                     'amount_currency': invoice.company_id.currency_id.compute(total_line[1], invoice.currency_id) if invoice.currency_id != invoice.company_id.currency_id else False,
                     'currency_id': invoice.currency_id != invoice.company_id.currency_id and invoice.currency_id.id,
                     'ref': invoice.reference
@@ -127,4 +127,30 @@ class AccountVoucher(models.Model):
             'state': 'open'
         })
 
-        # Step 5: Pay Invoice
+        # Step 5: Pay Invoice
+
+        values = {
+            'reference': account_move.name,
+            'type': 'receipt',
+            'journal_id': 7,
+            'company_id': account_move.company_id.id,
+            'pre_line': True,
+            'amount': 35000.0,
+            'period_id': account_move.period_id.id,
+            'date': account_move.date,
+            'partner_id': account_move.partner_id.id,
+            'account_id': 160,
+            'line_cr_ids': [[0, False, {
+                'date_due': l.date_maturity,
+                'account_id': l.account_id.id,
+                'date_original': l.invoice.date_invoice,
+                'move_line_id': l.id,
+                'amount_original': abs(l.credit or l.debit or 0.0),
+                'amount_unreconciled': abs(l.amount_residual),
+                'amount': abs(l.debit) if account_move.date == l.date_maturity else 0.0,
+                'reconcile': account_move.date == l.date_maturity
+            }] for l in account_move.line_id]
+        }
+
+        account_voucher = self.create(values)
+        return account_voucher.action_move_line_create()