[FIX] ensan_sale_management, sale_order_report: report footer, gifts, public user assertion error
This commit is contained in:
parent
1cb8739265
commit
736321c0ff
|
|
@ -1 +1,2 @@
|
|||
from . import models
|
||||
from . import models
|
||||
from . import controllers
|
||||
|
|
@ -0,0 +1 @@
|
|||
from . import controllers
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
from odoo.http import request, route
|
||||
from odoo.addons.payment.controllers.portal import PaymentProcessing
|
||||
from odoo.addons.website_sale.controllers.main import WebsiteSale
|
||||
|
||||
|
||||
class WebsiteSaleInherit(WebsiteSale):
|
||||
|
||||
@route()
|
||||
def payment_transaction(self, acquirer_id, save_token=False, so_id=None, access_token=None, token=None, **kwargs):
|
||||
""" Json method that creates a payment.transaction, used to create a
|
||||
transaction when the user clicks on 'pay now' button. After having
|
||||
created the transaction, the event continues and the user is redirected
|
||||
to the acquirer website.
|
||||
|
||||
:param int acquirer_id: id of a payment.acquirer record. If not set the
|
||||
user is redirected to the checkout page
|
||||
"""
|
||||
# Ensure a payment acquirer is selected
|
||||
if not acquirer_id:
|
||||
return False
|
||||
|
||||
try:
|
||||
acquirer_id = int(acquirer_id)
|
||||
except:
|
||||
return False
|
||||
|
||||
# Retrieve the sale order
|
||||
if so_id:
|
||||
env = request.env['sale.order']
|
||||
domain = [('id', '=', so_id)]
|
||||
if access_token:
|
||||
env = env.sudo()
|
||||
domain.append(('access_token', '=', access_token))
|
||||
order = env.search(domain, limit=1)
|
||||
else:
|
||||
order = request.website.sale_get_order()
|
||||
|
||||
# Ensure there is something to proceed
|
||||
if not order or (order and not order.order_line):
|
||||
return False
|
||||
|
||||
# assert order.partner_id.id != request.website.partner_id.id
|
||||
|
||||
# Create transaction
|
||||
vals = {'acquirer_id': acquirer_id,
|
||||
'return_url': '/shop/payment/validate'}
|
||||
|
||||
if save_token:
|
||||
vals['type'] = 'form_save'
|
||||
if token:
|
||||
vals['payment_token_id'] = int(token)
|
||||
|
||||
transaction = order._create_payment_transaction(vals)
|
||||
|
||||
# store the new transaction into the transaction list and if there's an old one, we remove it
|
||||
# until the day the ecommerce supports multiple orders at the same time
|
||||
last_tx_id = request.session.get('__website_sale_last_tx_id')
|
||||
last_tx = request.env['payment.transaction'].browse(last_tx_id).sudo().exists()
|
||||
if last_tx:
|
||||
PaymentProcessing.remove_payment_transaction(last_tx)
|
||||
PaymentProcessing.add_payment_transaction(transaction)
|
||||
request.session['__website_sale_last_tx_id'] = transaction.id
|
||||
return transaction.render_sale_button(order)
|
||||
|
|
@ -2,6 +2,7 @@ from odoo import models, fields, api, _
|
|||
from dateutil.relativedelta import relativedelta
|
||||
from datetime import datetime
|
||||
import logging
|
||||
from odoo import http
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
|
@ -22,8 +23,7 @@ class ProductTemplate_Inherit(models.Model):
|
|||
donated_amount = fields.Float(string="Collected Amount", tracking=True, compute="_compute_total_sold_amount", store=False)
|
||||
remaining_amount = fields.Float('Remaining Amount')
|
||||
done_percentage = fields.Float('Amount Percentage ',store=True)
|
||||
number_of_donations = fields.Integer(string="Number Of Donation", tracking=True,
|
||||
compute="_compute_number_of_donations", store=False)
|
||||
number_of_donations = fields.Integer(string="Number Of Donation", compute="_compute_number_of_donations")
|
||||
beneficiaries = fields.Integer('Beneficiaries', default=1)
|
||||
beneficiaries_been_supported = fields.Integer(string="Beneficiaries Been Supported", tracking=True,
|
||||
compute="_compute_beneficiaries_been_supported", store=False)
|
||||
|
|
@ -116,45 +116,10 @@ class ProductTemplate_Inherit(models.Model):
|
|||
|
||||
def _compute_number_of_donations(self):
|
||||
for rec in self:
|
||||
# all_invoices_paid = self.env['account.move'].search([('move_type', '=', 'out_invoice'), ('payment_state', '=', 'paid')])
|
||||
all_invoices_paid = self.env['account.move.line'].search(
|
||||
[
|
||||
('move_id.move_type', '=', 'out_invoice'), ('move_id.payment_state', '=', 'paid'),
|
||||
('product_id.product_tmpl_id', '=', rec.id)
|
||||
])
|
||||
invoices_counter = 0
|
||||
if all_invoices_paid:
|
||||
|
||||
# for invoice_line in all_invoices_paid.invoice_line_ids:
|
||||
# if invoice_line.product_id.product_tmpl_id.id == rec.id:
|
||||
# #Exists
|
||||
# invoices_counter +=1
|
||||
# continue
|
||||
invoices_counter = len(all_invoices_paid)
|
||||
|
||||
rec['number_of_donations'] = invoices_counter
|
||||
|
||||
|
||||
else:
|
||||
rec['number_of_donations'] = 0
|
||||
|
||||
"""
|
||||
all_invoices_paid = self.env['account.move.line'].search(
|
||||
[
|
||||
('move_id.move_type', '=', 'out_invoice'), ('move_id.payment_state', '=', 'paid'),
|
||||
('product_id.product_tmpl_id', '=', rec.id)
|
||||
])
|
||||
total_sum = 0
|
||||
if all_invoices_paid:
|
||||
for invoice_order_line in all_invoices_paid:
|
||||
if rec.donation_type == "Free Amount":
|
||||
total_sum += invoice_order_line.price_total
|
||||
else:
|
||||
total_sum += invoice_order_line.quantity
|
||||
rec['number_of_donations'] = total_sum
|
||||
else:
|
||||
rec['number_of_donations'] = 0
|
||||
"""
|
||||
all_invoices_paid = self.env['account.move.line'].search_count([('move_id.move_type', '=', 'out_invoice'),
|
||||
('move_id.payment_state', '=', 'paid'),
|
||||
('product_id.product_tmpl_id', '=', rec.id)])
|
||||
rec.number_of_donations = all_invoices_paid
|
||||
|
||||
def _compute_beneficiaries_been_supported(self):
|
||||
for rec in self:
|
||||
|
|
|
|||
|
|
@ -22,4 +22,20 @@ class SaleOrder(models.Model):
|
|||
else:
|
||||
return False
|
||||
|
||||
return self.order_line.filtered(show_line)
|
||||
return self.order_line.filtered(show_line)
|
||||
|
||||
def _get_downpayment_state(self):
|
||||
self.ensure_one()
|
||||
|
||||
if self.display_type:
|
||||
return ''
|
||||
|
||||
invoice_lines = self.invoice_lines
|
||||
if self.invoice_status == 'invoiced' and not invoice_lines:
|
||||
return ''
|
||||
if all(line.parent_state == 'draft' for line in invoice_lines):
|
||||
return 'draft'
|
||||
if all(line.parent_state == 'cancel' for line in invoice_lines):
|
||||
return 'cancel'
|
||||
|
||||
return ''
|
||||
|
|
@ -85,10 +85,8 @@
|
|||
<t t-raw="0" />
|
||||
</div>
|
||||
|
||||
|
||||
<div class="footer-container" align="center">
|
||||
<img t-att-src="'/sale_order_report/static/src/img/footer.png'" class="footer-image"
|
||||
align="center" />
|
||||
<div class="footer" >
|
||||
<img t-att-src="'/sale_order_report/static/src/img/footer.png'" align="center" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue