diff options
| author | Joren Van Onder <jov@odoo.com> | 2016-08-08 10:02:10 +0200 |
|---|---|---|
| committer | Simon Lejeune <sle@openerp.com> | 2016-08-24 11:19:15 +0200 |
| commit | cae2c749850181903b511ca128ebc83f734d777e (patch) | |
| tree | ec92f21a1a3d0fde28917eb2e584343ed730e068 | |
| parent | 0175d5b9d78f20f0c48d801d52d960e5630ade60 (diff) | |
[FIX] website_{payment,portal_sale}: move code depending on sale
From website_payment to website_portal_sale.
| -rw-r--r-- | addons/website_payment/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/website_payment/models/payment.py | 67 | ||||
| -rw-r--r-- | addons/website_payment/models/sale.py | 14 | ||||
| -rw-r--r-- | addons/website_portal_sale/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/website_portal_sale/models/payment.py | 69 | ||||
| -rw-r--r-- | addons/website_portal_sale/models/sale_order.py | 8 |
6 files changed, 78 insertions, 82 deletions
diff --git a/addons/website_payment/models/__init__.py b/addons/website_payment/models/__init__.py index 0f8a4704786..0a02268206c 100644 --- a/addons/website_payment/models/__init__.py +++ b/addons/website_payment/models/__init__.py @@ -1,4 +1,3 @@ import res_config import payment import website -import sale diff --git a/addons/website_payment/models/payment.py b/addons/website_payment/models/payment.py index d79c0f77b5a..cc7deca5556 100644 --- a/addons/website_payment/models/payment.py +++ b/addons/website_payment/models/payment.py @@ -1,74 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -import logging from odoo import api, fields, models -from odoo.tools import float_compare - -_logger = logging.getLogger(__name__) - class PaymentAcquirer(models.Model): _name = 'payment.acquirer' _inherit = ['payment.acquirer','website.published.mixin'] - -class PaymentTransaction(models.Model): - _inherit = 'payment.transaction' - - # link with the sale order - sale_order_id = fields.Many2one('sale.order', string='Sale Order') - - def _generate_and_pay_invoice(self, tx, acquirer_name): - tx.sale_order_id._force_lines_to_invoice_policy_order() - - created_invoice = tx.sale_order_id.action_invoice_create() - created_invoice = self.env['account.invoice'].browse(created_invoice) - - if created_invoice: - _logger.info('<%s> transaction completed, auto-generated invoice %s (ID %s) for %s (ID %s)', - acquirer_name, created_invoice.name, created_invoice.id, tx.sale_order_id.name, tx.sale_order_id.id) - - created_invoice.signal_workflow('invoice_open') - if tx.acquirer_id.journal_id: - created_invoice.pay_and_reconcile(tx.acquirer_id.journal_id, pay_amount=created_invoice.amount_total) - if created_invoice.payment_ids: - created_invoice.payment_ids[0].payment_transaction_id = tx - else: - _logger.warning('<%s> transaction completed, could not auto-generate payment for %s (ID %s) (no journal set on acquirer)', - acquirer_name, tx.sale_order_id.name, tx.sale_order_id.id) - else: - _logger.warning('<%s> transaction completed, could not auto-generate invoice for %s (ID %s)', - acquirer_name, tx.sale_order_id.name, tx.sale_order_id.id) - - @api.model - def form_feedback(self, data, acquirer_name): - """ Override to confirm the sale order, if defined, and if the transaction - is done. """ - tx = None - res = super(PaymentTransaction, self).form_feedback(data, acquirer_name) - - # fetch the tx, check its state, confirm the potential SO - try: - tx_find_method_name = '_%s_form_get_tx_from_data' % acquirer_name - if hasattr(self, tx_find_method_name): - tx = getattr(self, tx_find_method_name)(data) - _logger.info('<%s> transaction processed: tx ref:%s, tx amount: %s', acquirer_name, tx.reference if tx else 'n/a', tx.amount if tx else 'n/a') - - if tx and tx.sale_order_id and tx.sale_order_id.state in ['draft', 'sent']: - # verify SO/TX match, excluding tx.fees which are currently not included in SO - amount_matches = float_compare(tx.amount, tx.sale_order_id.amount_total, 2) == 0 - if amount_matches: - if tx.state == 'done' and tx.acquirer_id.auto_confirm in ['confirm_so', 'generate_and_pay_invoice']: - _logger.info('<%s> transaction completed, auto-confirming order %s (ID %s)', acquirer_name, tx.sale_order_id.name, tx.sale_order_id.id) - tx.sale_order_id.with_context(send_email=True).action_confirm() - - if tx.acquirer_id.auto_confirm == 'generate_and_pay_invoice': - self._generate_and_pay_invoice(tx, acquirer_name) - elif tx.state not in ['cancel', 'error'] and tx.sale_order_id.state == 'draft': - _logger.info('<%s> transaction pending/to confirm manually, sending quote email for order %s (ID %s)', acquirer_name, tx.sale_order_id.name, tx.sale_order_id.id) - tx.sale_order_id.force_quotation_send() - else: - _logger.warning('<%s> transaction MISMATCH for order %s (ID %s)', acquirer_name, tx.sale_order_id.name, tx.sale_order_id.id) - except Exception: - _logger.exception('Fail to confirm the order or send the confirmation email%s', tx and ' for the transaction %s' % tx.reference or '') - - return res diff --git a/addons/website_payment/models/sale.py b/addons/website_payment/models/sale.py deleted file mode 100644 index ffe46c2236d..00000000000 --- a/addons/website_payment/models/sale.py +++ /dev/null @@ -1,14 +0,0 @@ -# coding: utf-8 -# Part of Odoo. See LICENSE file for full copyright and licensing details. -import logging -from odoo import api, fields, models - -class SaleOrder(models.Model): - _inherit = 'sale.order' - - def _force_lines_to_invoice_policy_order(self): - for line in self.order_line: - if self.state in ['sale', 'done']: - line.qty_to_invoice = line.product_uom_qty - line.qty_invoiced - else: - line.qty_to_invoice = 0 diff --git a/addons/website_portal_sale/models/__init__.py b/addons/website_portal_sale/models/__init__.py index 76bcb3512a1..97f7899573c 100644 --- a/addons/website_portal_sale/models/__init__.py +++ b/addons/website_portal_sale/models/__init__.py @@ -2,3 +2,4 @@ # Part of Odoo. See LICENSE file for full copyright and licensing details. import sale_order +import payment diff --git a/addons/website_portal_sale/models/payment.py b/addons/website_portal_sale/models/payment.py new file mode 100644 index 00000000000..2b2ceeaa6f1 --- /dev/null +++ b/addons/website_portal_sale/models/payment.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. +import logging +from odoo import api, fields, models +from odoo.tools import float_compare + +_logger = logging.getLogger(__name__) + +class PaymentTransaction(models.Model): + _inherit = 'payment.transaction' + + # link with the sale order + sale_order_id = fields.Many2one('sale.order', string='Sale Order') + + def _generate_and_pay_invoice(self, tx, acquirer_name): + tx.sale_order_id._force_lines_to_invoice_policy_order() + + created_invoice = tx.sale_order_id.action_invoice_create() + created_invoice = self.env['account.invoice'].browse(created_invoice) + + if created_invoice: + _logger.info('<%s> transaction completed, auto-generated invoice %s (ID %s) for %s (ID %s)', + acquirer_name, created_invoice.name, created_invoice.id, tx.sale_order_id.name, tx.sale_order_id.id) + + created_invoice.signal_workflow('invoice_open') + if tx.acquirer_id.journal_id: + created_invoice.pay_and_reconcile(tx.acquirer_id.journal_id, pay_amount=created_invoice.amount_total) + if created_invoice.payment_ids: + created_invoice.payment_ids[0].payment_transaction_id = tx + else: + _logger.warning('<%s> transaction completed, could not auto-generate payment for %s (ID %s) (no journal set on acquirer)', + acquirer_name, tx.sale_order_id.name, tx.sale_order_id.id) + else: + _logger.warning('<%s> transaction completed, could not auto-generate invoice for %s (ID %s)', + acquirer_name, tx.sale_order_id.name, tx.sale_order_id.id) + + @api.model + def form_feedback(self, data, acquirer_name): + """ Override to confirm the sale order, if defined, and if the transaction + is done. """ + tx = None + res = super(PaymentTransaction, self).form_feedback(data, acquirer_name) + + # fetch the tx, check its state, confirm the potential SO + try: + tx_find_method_name = '_%s_form_get_tx_from_data' % acquirer_name + if hasattr(self, tx_find_method_name): + tx = getattr(self, tx_find_method_name)(data) + _logger.info('<%s> transaction processed: tx ref:%s, tx amount: %s', acquirer_name, tx.reference if tx else 'n/a', tx.amount if tx else 'n/a') + + if tx and tx.sale_order_id and tx.sale_order_id.state in ['draft', 'sent']: + # verify SO/TX match, excluding tx.fees which are currently not included in SO + amount_matches = float_compare(tx.amount, tx.sale_order_id.amount_total, 2) == 0 + if amount_matches: + if tx.state == 'done' and tx.acquirer_id.auto_confirm in ['confirm_so', 'generate_and_pay_invoice']: + _logger.info('<%s> transaction completed, auto-confirming order %s (ID %s)', acquirer_name, tx.sale_order_id.name, tx.sale_order_id.id) + tx.sale_order_id.with_context(send_email=True).action_confirm() + + if tx.acquirer_id.auto_confirm == 'generate_and_pay_invoice': + self._generate_and_pay_invoice(tx, acquirer_name) + elif tx.state not in ['cancel', 'error'] and tx.sale_order_id.state == 'draft': + _logger.info('<%s> transaction pending/to confirm manually, sending quote email for order %s (ID %s)', acquirer_name, tx.sale_order_id.name, tx.sale_order_id.id) + tx.sale_order_id.force_quotation_send() + else: + _logger.warning('<%s> transaction MISMATCH for order %s (ID %s)', acquirer_name, tx.sale_order_id.name, tx.sale_order_id.id) + except Exception: + _logger.exception('Fail to confirm the order or send the confirmation email%s', tx and ' for the transaction %s' % tx.reference or '') + + return res diff --git a/addons/website_portal_sale/models/sale_order.py b/addons/website_portal_sale/models/sale_order.py index b3d752f2396..944f7b6a6f7 100644 --- a/addons/website_portal_sale/models/sale_order.py +++ b/addons/website_portal_sale/models/sale_order.py @@ -20,3 +20,11 @@ class sale_order(models.Model): 'target': 'self', 'res_id': self.id, } + + def _force_lines_to_invoice_policy_order(self): + for line in self.order_line: + if self.state in ['sale', 'done']: + line.qty_to_invoice = line.product_uom_qty - line.qty_invoiced + else: + line.qty_to_invoice = 0 + |
