| 1 |
|
| 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 |
|
| 18 |
|
| 19 |
|
| 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 |
|
| 27 |
action['url'] = f'/@{action["url"]}' |
| 28 |
return action |
| 29 |
|
| 30 |
@api.depends('partner_id') |
| 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 |