add "Export All" button only for users with Administrator role
This commit is contained in:
parent
03a9ca3ace
commit
c6bce13803
@ -25,7 +25,10 @@ class PosExportBcWizard(models.TransientModel):
|
||||
def action_export_old_popcorn(self):
|
||||
return self._generate_export(old_format=True)
|
||||
|
||||
def _generate_export(self, old_format=False):
|
||||
def action_export_all(self):
|
||||
return self._generate_export(old_format=True, export_all=True)
|
||||
|
||||
def _generate_export(self, old_format=False, export_all=False):
|
||||
self.ensure_one()
|
||||
if not xlsxwriter:
|
||||
raise UserError(_("The Python library 'xlsxwriter' is required. Please install it."))
|
||||
@ -98,7 +101,7 @@ class PosExportBcWizard(models.TransientModel):
|
||||
|
||||
order_no = 1
|
||||
for order in orders:
|
||||
if 'refund_orders_count' in order._fields and order.refund_orders_count > 0:
|
||||
if not export_all and 'refund_orders_count' in order._fields and order.refund_orders_count > 0:
|
||||
continue
|
||||
|
||||
local_date = order.date_order.replace(tzinfo=pytz.UTC).astimezone(user_tz) if order.date_order else False
|
||||
@ -114,7 +117,7 @@ class PosExportBcWizard(models.TransientModel):
|
||||
discount_order = sum(abs(l.price_subtotal) for l in order.lines if l.price_unit < 0)
|
||||
tax = order.amount_tax
|
||||
paid = sum(p.amount for p in order.payment_ids if p.amount > 0)
|
||||
if paid == 0:
|
||||
if not export_all and paid == 0:
|
||||
continue
|
||||
rounding = order.amount_paid - order.amount_total
|
||||
charge = order.amount_paid
|
||||
@ -131,7 +134,7 @@ class PosExportBcWizard(models.TransientModel):
|
||||
|
||||
is_first_line = True
|
||||
for line in order.lines:
|
||||
if old_format and line.price_unit < 0:
|
||||
if not export_all and old_format and line.price_unit < 0:
|
||||
continue
|
||||
|
||||
if old_format and not is_first_line:
|
||||
@ -223,16 +226,22 @@ class PosExportBcWizard(models.TransientModel):
|
||||
company_ident = (company.company_registry or company.name or '').upper().replace(' ', '')
|
||||
|
||||
# Max length logic
|
||||
# For old_format: len("POS__YYMMDD_to_YYMMDD_OLD.xlsx") = 30 chars -> leaves 10 chars for company_ident
|
||||
# For new_format: len("POS__YYMMDD_to_YYMMDD.xlsx") = 26 chars -> leaves 14 chars for company_ident
|
||||
company_len = 10 if old_format else 14
|
||||
# base: len("POS__YYMMDD_to_YYMMDD.xlsx") = 26 chars -> leaves 14 chars
|
||||
company_len = 14
|
||||
if export_all:
|
||||
company_len = 7 # len("POS__YYMMDD_to_YYMMDD_OLD_ALL.xls") = 33 chars
|
||||
elif old_format:
|
||||
company_len = 10 # len("POS__YYMMDD_to_YYMMDD_OLD.xls") = 30 chars
|
||||
|
||||
company_ident = company_ident[:company_len]
|
||||
|
||||
start_str = self.start_date.strftime('%y%m%d')
|
||||
end_str = self.end_date.strftime('%y%m%d')
|
||||
|
||||
if old_format:
|
||||
file_name = f"POS_{company_ident}_{start_str}_to_{end_str}_OLD.xlsx"
|
||||
if export_all:
|
||||
file_name = f"POS_{company_ident}_{start_str}_to_{end_str}_OLD_ALL.xls"
|
||||
elif old_format:
|
||||
file_name = f"POS_{company_ident}_{start_str}_to_{end_str}_OLD.xls"
|
||||
else:
|
||||
file_name = f"POS_{company_ident}_{start_str}_to_{end_str}.xlsx"
|
||||
|
||||
|
||||
@ -19,6 +19,7 @@
|
||||
<footer>
|
||||
<button name="action_export_bc" string="Export to BC Format" type="object" class="btn-secondary" data-hotkey="q" invisible="1"/>
|
||||
<button name="action_export_old_popcorn" string="Export to Old Popcorn Format" type="object" class="btn-primary"/>
|
||||
<button name="action_export_all" string="Export All" type="object" class="btn-secondary" groups="base.group_system"/>
|
||||
<button string="Cancel" class="btn-secondary" special="cancel" data-hotkey="z"/>
|
||||
</footer>
|
||||
</form>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user