This commit merges the following models * account.invoice and account.move * account.invoice.line and account.move.line * account.voucher and account.move * account.voucher.line and account.move.line It was the opportunity for a big cleanup of the code, so it also restructures the whole account module, its different models/fields, the tests etc. for a better world and a better code readability. ==== Rationale ==== The rationale of this huge change is that we want journal entries / invoices to be easily edited, and changes reflected in the other model. It's a HUGE feature and very strategic for the fiduciary companies. For example, changing the account of a journal entry needs to be automatically reflected on the related invoice. The same reasoning applies to sale/purchase vouchers. ==== Changes made in features ===== When creating an invoice, you are now creating a journal entry directly. --> The object account.invoice no longer exists. In the same fashion when creating an invoice line, you're now adding journal items directly in the journal entry representing the invoice. If this invoice line has some tax, it may create additional journal items as well. --> The models account.invoice.line & account.invoice.tax no longer exist Identically, when creating a sale/purchase receipt with its lines, you are now creating a journal entry directly and there's no more usability difference between encoding a receipt or an invoice. --> The object account.voucher no longer exists. --> The object account.voucher.line no longer exists. --> The whole account_voucher module no longer exists. Positive side-effects coming from these changes are * draft invoices/bills/sale or purchase receipts now create a draft accounting entry. Validate these objects now simply post its journal entry. That means that draft invoices/bills/sale or purchase receipt can straightforwardly be included in reporting or budgets. * opening a journal entry in form view will now always open the correct view: if it's a sale/purchase journal entry we will have a customer invoice/vendor bill view or a sale/purchase receipt view, whatever the menu we're coming from. * code & business logic simplification. It is also condensed in a single place instead of being partially duplicated on invoices, vouchers and journal entries. There should be no feature loss, except the one allowing to group multiple journal items together based on the same product during the invoice validation. ==== Changes made in models ===== * account.invoice: model removed. Instead, now use account.move with following mapping field (account.invoice) field (account.move) ----------------------- -------------------- name invoice_payment_ref number name reference ref comment narration user_id invoice_user_id amount_ total_company_signed amount_total_signed residual amount_residual state state + invoice_payment_state /!\ selection changed date_invoice invoice_date date_due invoice_date_due sent invoice_sent origin invoice_origin payment_term_id invoice_payment_term_id partner_bank_id invoice_partner_bank_id incoterm_id invoice_incoterm_id vendor_bill_id invoice_vendor_bill_id source_email invoice_source_email vendor_display_name invoice_vendor_display_name invoice_icon invoice_vendor_icon cash_rounding_id invoice_cash_rounding_id sequence_number_next invoice_sequence_number_next sequence_number_next_prefix invoice_sequence_number_next_prefix 'invoices' subset of account.move can be accessed by using the selection field 'type' or one of the many helpers like is_invoice() * account.move: now has a valid state 'cancel' that has to be excluded from all business logic * account.move: field 'amount' renamed into 'amount_total' * account.move: field 'reverse_entry_id' renamed into 'reversed_entry_id' * account.move.line: now has a field 'display_type' that has to be excluded from all business logic, in order to support invoice layouting * account.invoice.line: model removed. Instead, now use account.move.line with following mapping field (account.invoice.line) field (account.move.line) ---------------------------- ------------------------- invoice_id move_id uom_id product_uom_id invoice_line_tax_ids tax_ids account_analytic_id analytic_account_id 'invoice lines' subset of all account.move.line from a journal entry can be accessed by using the boolean field 'exclude_from_invoice_tab' * account.invoice.tax: model removed. Instead, now use account.move.line with following mapping field (account.invoice.tax) field (account.move.line) --------------------------- ------------------------- invoice_id move_id account_analytic_id analytic_account_id amount price_unit base tax_base_amount 'tax lines' subset of all account.move.line from a journal entry can be accessed by using the relational field 'tax_line_id' * account.invoice.confirm: model removed. Instead, now use the 'post()' function of account.move * account.invoice.refund: model removed. Instead, now use account.move.reversal to reverse the entries with the same options as we had for invoices * account.voucher: model removed. Instead, now use account.move of type in ['out_receipt', 'in_receipt] * account.voucher.line: model removed. Instead, now use account.move.line ==== Changes made in functions ==== * on account.move, method _run_post_draft_to_post() renamed into _autopost_draft_entries() * on account.move, method action_account_invoice_payment() renamed into action_invoice_register_payment() * on account.move, method action_invoice_reconcile_to_check() renamed into action_open_matching_suspense_moves() * on account.move, method _get_domain_edition_mode_available() renamed into _get_domain_matching_supsense_moves() * on account.move, method _get_intrastat_country_id() renamed into _get_invoice_intrastat_country_id() * on account.move.line, method _get_domain_for_edition_mode() renamed into _get_suspense_moves_domain() * in account.bank.statement, contextual key 'edition_mode' renamed into 'suspense_moves_mode' Was task 1917430
111 lines
4.5 KiB
Python
111 lines
4.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
import base64
|
|
import io
|
|
from werkzeug.utils import redirect
|
|
|
|
from odoo import http
|
|
from odoo.http import request
|
|
from odoo.addons.sale.controllers.portal import CustomerPortal
|
|
from odoo.addons.website_sale.controllers.main import WebsiteSale
|
|
|
|
|
|
class WebsiteSaleDigitalConfirmation(WebsiteSale):
|
|
@http.route([
|
|
'/shop/confirmation',
|
|
], type='http', auth="public", website=True)
|
|
def payment_confirmation(self, **post):
|
|
response = super(WebsiteSaleDigitalConfirmation, self).payment_confirmation(**post)
|
|
order_lines = response.qcontext['order'].order_line
|
|
digital_content = any(x.product_id.type == 'digital' for x in order_lines)
|
|
response.qcontext.update(digital=digital_content)
|
|
return response
|
|
|
|
|
|
class WebsiteSaleDigital(CustomerPortal):
|
|
orders_page = '/my/orders'
|
|
|
|
@http.route([
|
|
'/my/orders/<int:order_id>',
|
|
], type='http', auth='public', website=True)
|
|
def portal_order_page(self, order_id=None, **post):
|
|
response = super(WebsiteSaleDigital, self).portal_order_page(order_id=order_id, **post)
|
|
if not 'sale_order' in response.qcontext:
|
|
return response
|
|
order = response.qcontext['sale_order']
|
|
invoiced_lines = request.env['account.move.line'].sudo().search([('invoice_id', 'in', order.invoice_ids.ids), ('invoice_id.state', '=', 'paid')])
|
|
products = invoiced_lines.mapped('product_id') | order.order_line.filtered(lambda r: not r.price_subtotal).mapped('product_id')
|
|
if not order.amount_total:
|
|
# in that case, we should add all download links to the products
|
|
# since there is nothing to pay, so we shouldn't wait for an invoice
|
|
products = order.order_line.mapped('product_id')
|
|
|
|
purchased_products_attachments = {}
|
|
for product in products:
|
|
# Search for product attachments
|
|
Attachment = request.env['ir.attachment']
|
|
product_id = product.id
|
|
template = product.product_tmpl_id
|
|
att = Attachment.search_read(
|
|
domain=['|', '&', ('res_model', '=', product._name), ('res_id', '=', product_id), '&', ('res_model', '=', template._name), ('res_id', '=', template.id), ('product_downloadable', '=', True)],
|
|
fields=['name', 'write_date'],
|
|
order='write_date desc',
|
|
)
|
|
|
|
# Ignore products with no attachments
|
|
if not att:
|
|
continue
|
|
|
|
purchased_products_attachments[product_id] = att
|
|
|
|
response.qcontext.update({
|
|
'digital_attachments': purchased_products_attachments,
|
|
})
|
|
return response
|
|
|
|
@http.route([
|
|
'/my/download',
|
|
], type='http', auth='public')
|
|
def download_attachment(self, attachment_id):
|
|
# Check if this is a valid attachment id
|
|
attachment = request.env['ir.attachment'].sudo().search_read(
|
|
[('id', '=', int(attachment_id))],
|
|
["name", "datas", "file_type", "res_model", "res_id", "type", "url"]
|
|
)
|
|
|
|
if attachment:
|
|
attachment = attachment[0]
|
|
else:
|
|
return redirect(self.orders_page)
|
|
|
|
# Check if the user has bought the associated product
|
|
res_model = attachment['res_model']
|
|
res_id = attachment['res_id']
|
|
purchased_products = request.env['account.move.line'].get_digital_purchases()
|
|
|
|
if res_model == 'product.product':
|
|
if res_id not in purchased_products:
|
|
return redirect(self.orders_page)
|
|
|
|
# Also check for attachments in the product templates
|
|
elif res_model == 'product.template':
|
|
template_ids = request.env['product.product'].sudo().browse(purchased_products).mapped('product_tmpl_id').ids
|
|
if res_id not in template_ids:
|
|
return redirect(self.orders_page)
|
|
|
|
else:
|
|
return redirect(self.orders_page)
|
|
|
|
# The client has bought the product, otherwise it would have been blocked by now
|
|
if attachment["type"] == "url":
|
|
if attachment["url"]:
|
|
return redirect(attachment["url"])
|
|
else:
|
|
return request.not_found()
|
|
elif attachment["datas"]:
|
|
data = io.BytesIO(base64.standard_b64decode(attachment["datas"]))
|
|
return http.send_file(data, filename=attachment['name'], as_attachment=True)
|
|
else:
|
|
return request.not_found()
|