[FIX] website_sale: make invoice website_id depend on originating SO instead of partner
Steps to Reproduce - Install E-Commerce app - Add Demo payment provider in Test mode - Go to Settings > Website > Invoicing and activate Automatic Invoice - Go to Settings > Website and set the domain for: - My Website -we'll refer to it as website_1- as http://[IP_address]:[port] such as http://127.0.0.1:8069 - My Website 2 -we'll refer to it as website_2- as http://[IP_address]:[port] such as http://127.0.0.2:8069 - Create a new product with Invoicing Policy as Ordered quantities - Go to website_2 and add the new product to the cart and checkout - With Debug mode on, Check the Emails sent via Settings > Technical > Email > Emails Current Behavior Two emails are automatically sent: - An SO email that opens website_2 when clicking on View Sales Order button which is correct as we purchased the product through website_2 - An Invoice email that opens website_1 when clicking one View Invoice button which is WRONG as it should follow its originating SO and opens website_2 as well Expected Behavior Both SO and invoice emails should refer to the website where the SO was created -website_2 in our use case- Observations The automatic invoice always refer to website_1 regardless of the website where the SO was originally created. Investigation The website_id of the invoice is decided by the corresponding field https://github.com/odoo/odoo/blob/322889ea0a24c5eff2e3289502a2f606cb4048d0/addons/website_sale/models/account_move.py#L10-L13 - As noticed it's a related field to the partner_id.website_id which is False - That's why the invoice website_id is also False leading to the preview button to fall back to website_1 - The partner_id.website_id is always False unless you manually added the field to the view and then set the website_id. Our case will work correctly if you set the website_id for the user/customer to website_2 - I also tried to sign up at website_2 to see if the website_id will be set accordingly but it stayed as False Proposed Solution make the invoice website_id relates to the originating SO instead of the partner opw-3685742 closes odoo/odoo#154376 X-original-commit: 361e8f68af9c9656764906c8a44d22e1fed090a8 Signed-off-by: Ali Hassan Youssef (alhy) <alhy@odoo.com>
This commit is contained in:
@@ -1,14 +1,14 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import fields, models
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class AccountMove(models.Model):
|
||||
_inherit = 'account.move'
|
||||
|
||||
website_id = fields.Many2one(
|
||||
'website', related='partner_id.website_id', string='Website',
|
||||
'website', compute='_compute_website_id', string='Website',
|
||||
help='Website through which this invoice was created for eCommerce orders.',
|
||||
store=True, readonly=True, tracking=True)
|
||||
|
||||
@@ -18,3 +18,12 @@ class AccountMove(models.Model):
|
||||
# URL should always be relative, safety check
|
||||
action['url'] = f'/@{action["url"]}'
|
||||
return action
|
||||
|
||||
@api.depends('partner_id') # Dummy depends to trigger compute, will be dropped in master
|
||||
def _compute_website_id(self):
|
||||
for move in self:
|
||||
source_websites = move.line_ids.sale_line_ids.order_id.website_id
|
||||
if len(source_websites) == 1:
|
||||
move.website_id = source_websites
|
||||
else:
|
||||
move.website_id = False
|
||||
|
||||
@@ -26,3 +26,4 @@ from . import test_website_editor
|
||||
from . import test_website_sale_reorder_from_portal
|
||||
from . import test_website_sale_snippets
|
||||
from . import test_website_sale_fiscal_position
|
||||
from . import test_website_sale_invoice
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.tests import tagged
|
||||
from odoo.tools import mute_logger
|
||||
|
||||
from odoo.addons.account_payment.tests.common import AccountPaymentCommon
|
||||
from odoo.addons.sale.tests.common import SaleCommon
|
||||
|
||||
|
||||
@tagged('-at_install', 'post_install')
|
||||
class TestWebsiteSaleInvoice(AccountPaymentCommon, SaleCommon):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
|
||||
cls.website = cls.env['website'].create({
|
||||
'name': 'Test Website'
|
||||
})
|
||||
|
||||
def test_automatic_invoice_website_id(self):
|
||||
# Set automatic invoice
|
||||
self.env['ir.config_parameter'].sudo().set_param('sale.automatic_invoice', 'True')
|
||||
|
||||
# Create SO on Test Website
|
||||
self.sale_order.website_id = self.website.id
|
||||
|
||||
# Create the payment
|
||||
self.amount = self.sale_order.amount_total
|
||||
tx = self._create_transaction(flow='redirect', sale_order_ids=[self.sale_order.id], state='done')
|
||||
with mute_logger('odoo.addons.sale.models.payment_transaction'):
|
||||
tx._reconcile_after_done()
|
||||
|
||||
self.assertEqual(self.sale_order.website_id.id, self.website.id)
|
||||
self.assertEqual(self.sale_order.invoice_ids.website_id.id, self.website.id)
|
||||
Reference in New Issue
Block a user