Merge lp:~magentoerpconnect-community/magentoerpconnect/legacy61-fix-1011491 into lp:magentoerpconnect/oerp6.1-oldstable

Proposed by Guewen Baconnier @ Camptocamp on 2012-06-11
Status: Merged
Merged at revision: 664
Proposed branch: lp:~magentoerpconnect-community/magentoerpconnect/legacy61-fix-1011491
Merge into: lp:magentoerpconnect/oerp6.1-oldstable
Diff against target: 64 lines (+35/-12)
1 file modified
magentoerpconnect/sale.py (+35/-12)
To merge this branch: bzr merge lp:~magentoerpconnect-community/magentoerpconnect/legacy61-fix-1011491
Reviewer Review Type Date Requested Status
Alexandre Fayolle - camptocamp code review, no test 2012-06-11 Approve on 2012-12-05
Review via email: mp+109634@code.launchpad.net

Description of the change

Generate automatic payments according to the sale order's payment terms.

More info at :
https://bugs.launchpad.net/magentoerpconnect/+bug/1011491

To post a comment you must log in.

I would be glad to have a review on this branch.

Thanks

LGTM

review: Approve (code review, no test)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'magentoerpconnect/sale.py'
2--- magentoerpconnect/sale.py 2012-05-25 09:01:25 +0000
3+++ magentoerpconnect/sale.py 2012-06-11 13:33:19 +0000
4@@ -621,6 +621,26 @@
5 amount = payment_info.get('amount_ordered', False)
6 return paid, amount
7
8+ def _get_payment_amounts(self, cr, uid, order, total_amount, context=None):
9+ """
10+ Compute the payments to create for an order based on an amount
11+ which represents the total paid.
12+
13+ Uses the account.payment.term if there is one on the order so it will
14+ correctly divide the payment between the billing deadlines.
15+
16+ :param browse_record order: browsable order
17+ :param float total_amount: total amount of the payment
18+ :return: list of tuple of payment [(payment date, payment amount), ...]
19+ """
20+ if order.payment_term:
21+ return self.pool.get('account.payment.term').compute(
22+ cr, uid, order.payment_term.id, total_amount,
23+ date_ref=order.date_order, context=context)
24+ else:
25+ # full payment should be generated
26+ return [(order.date_order, total_amount)]
27+
28 def create_payments(self, cr, uid, order_id, data_record, context=None):
29 if context is None:
30 context = {}
31@@ -630,18 +650,21 @@
32 paid, amount = self._parse_external_payment(
33 cr, uid, data_record, context=context)
34 if paid:
35- order = self.pool.get('sale.order').browse(
36- cr, uid, order_id, context)
37- self.generate_payment_with_pay_code(
38- cr, uid,
39- payment_info['method'],
40- order.partner_id.id,
41- float(amount),
42- "mag_" + payment_info['payment_id'],
43- "mag_" + data_record['increment_id'],
44- order.date_order,
45- paid,
46- context=context)
47+ # external amount is a str
48+ amount = float(amount)
49+ order = self.pool.get('sale.order').browse( cr, uid, order_id, context)
50+ payments = self._get_payment_amounts(cr, uid, order, amount, context=context)
51+ for pay_date, pay_amount in payments:
52+ self.generate_payment_with_pay_code(
53+ cr, uid,
54+ payment_info['method'],
55+ order.partner_id.id,
56+ pay_amount,
57+ "mag_" + payment_info['payment_id'],
58+ "mag_" + data_record['increment_id'],
59+ pay_date,
60+ paid,
61+ context=context)
62 else:
63 paid = super(sale_order, self).create_payments(
64 cr, uid, order_id, data_record, context=context)