[MOV] sale_*: move sale-related payment code to sale_payment

website_portal_sale contains code on sale.order and crm.team models
related to payments. This code is moved into the sale_payment module
that is the bridge between sale and payment and therefore is the
location where it belongs. First step toward removing content of
website_portal_sale module.
This commit is contained in:
Thibault Delavallée
2017-08-08 15:18:00 +02:00
parent 729561e6bd
commit 62c3ada851
10 changed files with 31 additions and 29 deletions
+2
View File
@@ -17,6 +17,8 @@ Provide tools for sale-related payment
'depends': ['payment', 'sale'],
'data': [
'views/payment_views.xml',
'views/crm_team_views.xml',
'views/sale_order_views.xml',
],
'installable': True,
'auto_install': False,
+1
View File
@@ -2,4 +2,5 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import payment
from . import crm_team
from . import sale_order
+27
View File
@@ -9,6 +9,15 @@ class SaleOrder(models.Model):
payment_tx_id = fields.Many2one('payment.transaction', string='Last Transaction', copy=False)
payment_acquirer_id = fields.Many2one('payment.acquirer', string='Payment Acquirer', related='payment_tx_id.acquirer_id', store=True)
payment_transaction_count = fields.Integer(
string="Number of payment transactions",
compute='_compute_payment_transaction_count')
def _compute_payment_transaction_count(self):
transaction_data = self.env['payment.transaction'].read_group([('sale_order_id', 'in', self.ids)], ['sale_order_id'], ['sale_order_id'])
mapped_data = dict([(m['sale_order_id'][0], m['sale_order_id_count']) for m in transaction_data])
for order in self:
order.payment_transaction_count = mapped_data.get(order.id, 0)
def _force_lines_to_invoice_policy_order(self):
for line in self.order_line:
@@ -16,3 +25,21 @@ class SaleOrder(models.Model):
line.qty_to_invoice = line.product_uom_qty - line.qty_invoiced
else:
line.qty_to_invoice = 0
def action_view_transaction(self):
action = {
'type': 'ir.actions.act_window',
'name': 'Payment Transactions',
'res_model': 'payment.transaction',
}
if self.payment_transaction_count == 1:
action.update({
'res_id': self.env['payment.transaction'].search([('sale_order_id', '=', self.id)]).id,
'view_mode': 'form',
})
else:
action.update({
'view_mode': 'tree,form',
'domain': [('sale_order_id', '=', self.id)],
})
return action
@@ -16,8 +16,6 @@ Add your sales document in the frontend portal. Your customers will be able to c
'website_payment',
],
'data': [
'views/crm_team_views.xml',
'views/sale_order_views.xml',
'views/website_portal_sale_templates.xml',
'security/ir.model.access.csv',
'security/sale_order_security.xml',
@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import crm_team
from . import sale_order
@@ -12,18 +12,11 @@ class SaleOrder(models.Model):
_inherit = 'sale.order'
website_url = fields.Char('Website URL', compute='_website_url', help='The full URL to access the document through the website.')
payment_transaction_count = fields.Integer(compute='_compute_payment_transaction_count', string="Number of payment transactions")
def _website_url(self):
for so in self:
so.website_url = '/my/orders/%s' % (so.id)
def _compute_payment_transaction_count(self):
transaction_data = self.env['payment.transaction'].read_group([('sale_order_id', 'in', self.ids)], ['sale_order_id'], ['sale_order_id'])
mapped_data = dict([(m['sale_order_id'][0], m['sale_order_id_count']) for m in transaction_data])
for order in self:
order.payment_transaction_count = mapped_data.get(order.id, 0)
@api.multi
def get_access_action(self, access_uid=None):
""" Instead of the classic form view, redirect to the online order for
@@ -72,24 +65,6 @@ class SaleOrder(models.Model):
model=self._name,
res_id=self.id)[self.partner_id.id]
def action_view_transaction(self):
action = {
'type': 'ir.actions.act_window',
'name': 'Payment Transactions',
'res_model': 'payment.transaction',
}
if self.payment_transaction_count == 1:
action.update({
'res_id': self.env['payment.transaction'].search([('sale_order_id', '=', self.id)]).id,
'view_mode': 'form',
})
else:
action.update({
'view_mode': 'tree,form',
'domain': [('sale_order_id', '=', self.id)],
})
return action
class SaleOrderLine(models.Model):
+1 -1
View File
@@ -6,7 +6,7 @@
'website': 'https://www.odoo.com/page/e-commerce',
'version': '1.0',
'description': "",
'depends': ['website', 'sale', 'payment', 'website_payment', 'website_portal_sale', 'website_account', 'website_mail', 'website_form', 'website_rating'],
'depends': ['website', 'sale', 'sale_payment', 'payment', 'website_payment', 'website_portal_sale', 'website_account', 'website_mail', 'website_form', 'website_rating'],
'data': [
'security/ir.model.access.csv',
'security/website_sale.xml',