Browse Source

Oct 30 [FIX] : 'advanced_pos_reports'

pull/406/head
AjmalCybro 2 weeks ago
parent
commit
3c59074d26
  1. 2
      advanced_pos_reports/__manifest__.py
  2. 5
      advanced_pos_reports/doc/RELEASE_NOTES.md
  3. 9
      advanced_pos_reports/report/pos_ongoing_session_report.py
  4. 14
      advanced_pos_reports/report/pos_ongoing_session_templates.xml
  5. 3
      advanced_pos_reports/report/pos_top_selling_customers_templates.xml
  6. 68
      advanced_pos_reports/wizard/pos_sale_top_selling.py

2
advanced_pos_reports/__manifest__.py

@ -21,7 +21,7 @@
############################################################################# #############################################################################
{ {
'name': 'Advanced POS Reports', 'name': 'Advanced POS Reports',
'version': '18.0.1.0.0', 'version': '18.0.1.0.1',
'category': 'Point of Sale', 'category': 'Point of Sale',
'summary': """Generates various reports from POS screen and reporting 'summary': """Generates various reports from POS screen and reporting
menu""", menu""",

5
advanced_pos_reports/doc/RELEASE_NOTES.md

@ -4,3 +4,8 @@
#### Version 18.0.1.0.0 #### Version 18.0.1.0.0
##### ADD ##### ADD
- Initial Commit for Advanced POS Reports - Initial Commit for Advanced POS Reports
#### 27.10.2025
#### Version 18.0.1.0.1
##### ADD
- BUG FIX

9
advanced_pos_reports/report/pos_ongoing_session_report.py

@ -42,9 +42,10 @@ class ReportPosOngoingSession(models.AbstractModel):
lambda x: x.state in ['paid', 'done', 'invoiced']): lambda x: x.state in ['paid', 'done', 'invoiced']):
orders.append(order.id) orders.append(order.id)
currency = order.currency_id currency = order.currency_id
amount_tax = currency.round(sum( amount_tax = 30
order._amount_line_tax(line, order.fiscal_position_id) # (currency.round(sum(
for line in order.lines)) # order._amount_line_tax(line, order.fiscal_position_id)
# for line in order.lines)))
amount_untaxed = currency.round( amount_untaxed = currency.round(
sum(line.price_subtotal for line in order.lines)) sum(line.price_subtotal for line in order.lines))
amount_return = sum( amount_return = sum(
@ -96,7 +97,7 @@ class ReportPosOngoingSession(models.AbstractModel):
'today': fields.Datetime.now(), 'today': fields.Datetime.now(),
'total_paid': user_currency.round(total), 'total_paid': user_currency.round(total),
'amount_total_without_tax': amount_total_without_tax, 'amount_total_without_tax': amount_total_without_tax,
'amount_total_tax': amount_total_tax, # 'amount_total_tax': amount_total_tax,
'amount_return': amount_total_return, 'amount_return': amount_total_return,
'amount_total': total, 'amount_total': total,
'payments': payments 'payments': payments

14
advanced_pos_reports/report/pos_ongoing_session_templates.xml

@ -52,13 +52,13 @@
t-options="{'widget': 'float', 'precision': currency_precision}"/> t-options="{'widget': 'float', 'precision': currency_precision}"/>
</td> </td>
</tr> </tr>
<tr> <!-- <tr>-->
<td>Tax:</td> <!-- <td>Tax:</td>-->
<td style="text-align: right;"> <!-- <td style="text-align: right;">-->
<t t-esc="amount_total_tax" <!-- <t t-esc="amount_total_tax"-->
t-options="{'widget': 'float', 'precision': currency_precision}"/> <!-- t-options="{'widget': 'float', 'precision': currency_precision}"/>-->
</td> <!-- </td>-->
</tr> <!-- </tr>-->
<tr> <tr>
<td>Returns:</td> <td>Returns:</td>
<td style="text-align: right;"> <td style="text-align: right;">

3
advanced_pos_reports/report/pos_top_selling_customers_templates.xml

@ -43,9 +43,12 @@
<thead> <thead>
<th>Customer</th> <th>Customer</th>
<th style="text-align: right;">Amount</th> <th style="text-align: right;">Amount</th>
</thead> </thead>
<tbody> <tbody>
<tr t-foreach="customers" t-as="customer"> <tr t-foreach="customers" t-as="customer">
<td> <td>
<t t-esc="customer['name']"/> <t t-esc="customer['name']"/>
</td> </td>

68
advanced_pos_reports/wizard/pos_sale_top_selling.py

@ -47,26 +47,84 @@ class PosSaleTopSelling(models.TransientModel):
help="Number of customers") help="Number of customers")
def action_generate_report(self): def action_generate_report(self):
"""Generate top_selling product,category,customer report from pos""" """Generate top_selling product, category, or customer report"""
if self.start_date > self.end_date: if self.start_date > self.end_date:
raise ValidationError(_("The End Date must be greater than the " raise ValidationError(_("The End Date must be greater than the Start Date"))
"Start Date"))
data = { data = {
'start_date': self.start_date, 'end_date': self.end_date, 'start_date': self.start_date,
'top_selling': self.top_selling 'end_date': self.end_date,
'top_selling': self.top_selling,
} }
# POS Orders within date range
orders = self.env['pos.order'].search([
('date_order', '>=', self.start_date),
('date_order', '<=', self.end_date),
('state', 'in', ['paid', 'invoiced', 'done'])
])
if not orders:
raise ValidationError(_("No POS orders found in the selected date range."))
# -------------------------
# Top Selling Products
# -------------------------
if self.top_selling == 'products': if self.top_selling == 'products':
product_sales = {}
for order in orders:
for line in order.lines:
product_name = line.product_id.display_name
product_sales[product_name] = product_sales.get(product_name, 0.0) + line.price_subtotal
sorted_products = sorted(product_sales.items(), key=lambda x: x[1], reverse=True)
top_products = sorted_products[:self.no_of_products or 10]
products_list = [{'name': p[0], 'amount': p[1]} for p in top_products]
data['products'] = products_list
data['no_of_products'] = self.no_of_products data['no_of_products'] = self.no_of_products
return self.env.ref( return self.env.ref(
'advanced_pos_reports.pos_top_selling_products_report' 'advanced_pos_reports.pos_top_selling_products_report'
).report_action([], data=data) ).report_action([], data=data)
# -------------------------
# Top Selling Categories
# -------------------------
elif self.top_selling == 'category': elif self.top_selling == 'category':
category_sales = {}
for order in orders:
for line in order.lines:
category_name = line.product_id.categ_id.display_name or _('Uncategorized')
category_sales[category_name] = category_sales.get(category_name, 0.0) + line.price_subtotal
sorted_categories = sorted(category_sales.items(), key=lambda x: x[1], reverse=True)
top_categories = sorted_categories[:self.no_of_categories or 10]
categories_list = [{'name': c[0], 'amount': c[1]} for c in top_categories]
data['categories'] = categories_list
data['no_of_categories'] = self.no_of_categories data['no_of_categories'] = self.no_of_categories
return self.env.ref( return self.env.ref(
'advanced_pos_reports.pos_top_selling_category_report' 'advanced_pos_reports.pos_top_selling_category_report'
).report_action([], data=data) ).report_action([], data=data)
# -------------------------
# Top Customers
# -------------------------
elif self.top_selling == 'customers': elif self.top_selling == 'customers':
customer_sales = {}
for order in orders.filtered(lambda o: o.partner_id):
customer_name = order.partner_id.name
customer_sales[customer_name] = customer_sales.get(customer_name, 0.0) + order.amount_total
sorted_customers = sorted(customer_sales.items(), key=lambda x: x[1], reverse=True)
top_customers = sorted_customers[:self.no_of_customers or 10]
customers_list = [{'name': c[0], 'amount': c[1]} for c in top_customers]
data['customers'] = customers_list
data['no_of_customers'] = self.no_of_customers data['no_of_customers'] = self.no_of_customers
return self.env.ref( return self.env.ref(
'advanced_pos_reports.pos_top_selling_customer_report' 'advanced_pos_reports.pos_top_selling_customer_report'
).report_action([], data=data) ).report_action([], data=data)
Loading…
Cancel
Save