Debian Codegraph @

addons/website_sale/models/account_move.py

raw symbols SCIP
1 # Part of Odoo. See LICENSE file for full copyright and licensing details.
2
3 from odoo import api, fields, models
4 from odoo.tools.sql import column_exists, create_column
5
6
7 class AccountMove(models.Model):
8 _inherit = 'account.move'
9
10 website_id = fields.Many2one(
11 'website', compute='_compute_website_id', string='Website',
12 help='Website through which this invoice was created for eCommerce orders.',
13 store=True, readonly=True, tracking=True)
14
15 def _auto_init(self):
16 if not column_exists(self.env.cr, "account_move", "website_id"):
17 # Creating the column via `_auto_init` prevents a MemoryError in databases where many
18 # invoices exist when `website_sale` is installed, as it skips the computation of the
19 # `website_id` field.
20 create_column(self.env.cr, "account_move", "website_id", "int4")
21 super()._auto_init()
22
23 def preview_invoice(self):
24 action = super().preview_invoice()
25 if action['url'].startswith('/'):
26 # URL should always be relative, safety check
27 action['url'] = f'/@{action["url"]}'
28 return action
29
30 @api.depends('partner_id') # Dummy depends to trigger compute, will be dropped in master
31 def _compute_website_id(self):
32 for move in self:
33 source_websites = move.line_ids.sale_line_ids.order_id.website_id
34 if len(source_websites) == 1:
35 move.website_id = source_websites
36 else:
37 move.website_id = False