changes in ShopDailyCategoryReport

This commit is contained in:
Elvis 2023-06-28 10:40:27 -05:00
parent e06de6fcf4
commit e1db801e55
2 changed files with 28 additions and 19 deletions

45
shop.py
View File

@ -401,6 +401,7 @@ class ShopDailyCategoryStart(ModelView):
__name__ = 'sale_pos.shop_daily_category.start'
company = fields.Many2One('company.company', 'Company', required=True)
sale_date = fields.Date('Sale Date', required=True)
end_date = fields.Date('End Date', required=True)
shop = fields.Many2One('sale.shop', 'Shop', required=True)
early_morning_included = fields.Boolean('Early Morning Included')
@ -457,7 +458,7 @@ class ShopDailyCategoryReport(Report):
where_ = sale.state.in_(['processing', 'done'])
where_ = line.product.in_(products_exception)
where_ &= sale.company == data['company']
# where_ &= sale.invoice_type == 'P'
where_ &= sale.invoice_type == 'P'
where_ &= sale.number != Null
if data['shop']:
where_ &= sale.shop == data['shop']
@ -469,7 +470,7 @@ class ShopDailyCategoryReport(Report):
_start_date = datetime.combine(data['sale_date'], fixed_hour)
_start_date = Company.convert_timezone(_start_date, True)
end_date = data['sale_date'] + timedelta(days=1)
end_date = data['sale_date'] + timedelta(days=1) if not data['sale_date'] else data['sale_date'] + timedelta(days=1)
_end_date = datetime.combine(end_date, fixed_hour)
_end_date = Company.convert_timezone(_end_date, True)
@ -510,16 +511,20 @@ class ShopDailyCategoryReport(Report):
('shop', '=', data['shop']),
('company', '=', data['company']),
('number', '!=', None),
# ('invoice_type', '=', 'P'),
('invoice_type', '=', 'P'),
]
if not data['early_morning_included']:
dom_sales.append(('sale_date', '=', data['sale_date']))
if data['end_date']:
dom_sales.append(('sale_date', '>=', data['sale_date']))
dom_sales.append(('sale_date', '<=', data['end_date']))
else:
dom_sales.append(('sale_date', '=', data['sale_date']))
else:
# Select sales including early morning of next day
_start_date = datetime.combine(data['sale_date'], fixed_hour)
_start_date = Company.convert_timezone(_start_date, True)
end_date = data['sale_date'] + timedelta(days=1)
end_date = data['sale_date'] + timedelta(days=1) if not data['end_date'] else data['end_date'] + timedelta(days=1)
_end_date = datetime.combine(end_date, fixed_hour)
_end_date = Company.convert_timezone(_end_date, True)
@ -527,7 +532,7 @@ class ShopDailyCategoryReport(Report):
dom_sales.append(('sale_date', '<=', end_date))
dom_sales.append(('create_date', '>=', _start_date))
dom_sales.append(('create_date', '<=', _end_date))
print(dom_sales)
states_sale = ['processing', 'done']
dom_sales.append(('state', 'in', states_sale))
@ -566,7 +571,7 @@ class ShopDailyCategoryReport(Report):
if line.product.categories:
category = line.product.categories[0]
category_id = category.id
if category_id not in categories.keys():
if category_id not in categories.keys() and category_id != '0':
categories[category_id] = {
'name': category.name,
'base': [line.amount],
@ -579,18 +584,19 @@ class ShopDailyCategoryReport(Report):
}
total_payments.append(line.amount_w_tax)
else:
categories[category_id]['base'].append(line.amount)
if line.product.template.id in categories[category_id]['products'].keys():
categories[category_id]['products'][line.product.template.id]['quantity'] += line.quantity
categories[category_id]['products'][line.product.template.id]['amount'] += line.amount_w_tax
total_payments.append(line.amount_w_tax)
else:
categories[category_id]['products'][line.product.template.id] = {
'name': line.product.template.name,
'quantity': line.quantity,
'amount': line.amount_w_tax,
}
total_payments.append(line.amount_w_tax)
if category_id != '0':
categories[category_id]['base'].append(line.amount)
if line.product.template.id in categories[category_id]['products'].keys():
categories[category_id]['products'][line.product.template.id]['quantity'] += line.quantity
categories[category_id]['products'][line.product.template.id]['amount'] += line.amount_w_tax
total_payments.append(line.amount_w_tax)
else:
categories[category_id]['products'][line.product.template.id] = {
'name': line.product.template.name,
'quantity': line.quantity,
'amount': line.amount_w_tax,
}
total_payments.append(line.amount_w_tax)
if numbers:
min_number = min(numbers)
max_number = max(numbers)
@ -599,6 +605,7 @@ class ShopDailyCategoryReport(Report):
min_number = ''
max_number = ''
report_context['date'] = data['sale_date']
report_context['end_date'] = data['end_date'] if data['end_date'] else data['sale_date']
report_context['company'] = company.party
report_context['shop'] = Shop(data['shop']).name
report_context['start_number'] = min_number

View File

@ -8,6 +8,8 @@ The COPYRIGHT file at the top level of this repository contains the full copyrig
<field name="company" widget="selection"/>
<label name="sale_date"/>
<field name="sale_date"/>
<label name="end_date"/>
<field name="end_date"/>
<label name="early_morning_included"/>
<field name="early_morning_included"/>
</form>