~magentoerpconnect-core-editors/magentoerpconnect/trunk_version

« back to all changes in this revision

Viewing changes to magentoerpconnect/sale.py

  • Committer: Guewen Baconnier @ Camptocamp
  • Date: 2012-06-11 13:23:58 UTC
  • mto: This revision was merged to the branch mainline in revision 664.
  • Revision ID: guewen.baconnier@camptocamp.com-20120611132358-4yms01vcmkjd6lj7
[FIX] automatic payment(s) for an external payment should be generated according to the sale order's payment terms, so the move lines match with the invoice move lines

Show diffs side-by-side

added added

removed removed

Lines of Context:
621
621
                amount = payment_info.get('amount_ordered', False)
622
622
        return paid, amount
623
623
 
 
624
    def _get_payment_amounts(self, cr, uid, order, total_amount, context=None):
 
625
        """
 
626
        Compute the payments to create for an order based on an amount
 
627
        which represents the total paid.
 
628
 
 
629
        Uses the account.payment.term if there is one on the order so it will
 
630
        correctly divide the payment between the billing deadlines.
 
631
 
 
632
        :param browse_record order: browsable order
 
633
        :param float total_amount: total amount of the payment
 
634
        :return: list of tuple of payment [(payment date, payment amount), ...]
 
635
        """
 
636
        if order.payment_term:
 
637
            return self.pool.get('account.payment.term').compute(
 
638
                cr, uid, order.payment_term.id, total_amount,
 
639
                date_ref=order.date_order, context=context)
 
640
        else:
 
641
            # full payment should be generated
 
642
            return [(order.date_order, total_amount)]
 
643
 
624
644
    def create_payments(self, cr, uid, order_id, data_record, context=None):
625
645
        if context is None:
626
646
            context = {}
630
650
            paid, amount = self._parse_external_payment(
631
651
                cr, uid, data_record, context=context)
632
652
            if paid:
633
 
                order = self.pool.get('sale.order').browse(
634
 
                    cr, uid, order_id, context)
635
 
                self.generate_payment_with_pay_code(
636
 
                    cr, uid,
637
 
                    payment_info['method'],
638
 
                    order.partner_id.id,
639
 
                    float(amount),
640
 
                    "mag_" + payment_info['payment_id'],
641
 
                    "mag_" + data_record['increment_id'],
642
 
                    order.date_order,
643
 
                    paid,
644
 
                    context=context)
 
653
                # external amount is a str
 
654
                amount = float(amount)
 
655
                order = self.pool.get('sale.order').browse( cr, uid, order_id, context)
 
656
                payments = self._get_payment_amounts(cr, uid, order, amount, context=context)
 
657
                for pay_date, pay_amount in payments:
 
658
                    self.generate_payment_with_pay_code(
 
659
                        cr, uid,
 
660
                        payment_info['method'],
 
661
                        order.partner_id.id,
 
662
                        pay_amount,
 
663
                        "mag_" + payment_info['payment_id'],
 
664
                        "mag_" + data_record['increment_id'],
 
665
                        pay_date,
 
666
                        paid,
 
667
                        context=context)
645
668
        else:
646
669
            paid = super(sale_order, self).create_payments(
647
670
                cr, uid, order_id, data_record, context=context)