add "Export All" button only for users with Administrator role

This commit is contained in:
Abdul Aziz Amrullah 2026-06-19 10:29:58 +07:00
parent 03a9ca3ace
commit c6bce13803
2 changed files with 19 additions and 9 deletions

View File

@ -25,7 +25,10 @@ class PosExportBcWizard(models.TransientModel):
def action_export_old_popcorn(self): def action_export_old_popcorn(self):
return self._generate_export(old_format=True) 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() self.ensure_one()
if not xlsxwriter: if not xlsxwriter:
raise UserError(_("The Python library 'xlsxwriter' is required. Please install it.")) raise UserError(_("The Python library 'xlsxwriter' is required. Please install it."))
@ -98,7 +101,7 @@ class PosExportBcWizard(models.TransientModel):
order_no = 1 order_no = 1
for order in orders: 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 continue
local_date = order.date_order.replace(tzinfo=pytz.UTC).astimezone(user_tz) if order.date_order else False 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) discount_order = sum(abs(l.price_subtotal) for l in order.lines if l.price_unit < 0)
tax = order.amount_tax tax = order.amount_tax
paid = sum(p.amount for p in order.payment_ids if p.amount > 0) 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 continue
rounding = order.amount_paid - order.amount_total rounding = order.amount_paid - order.amount_total
charge = order.amount_paid charge = order.amount_paid
@ -131,7 +134,7 @@ class PosExportBcWizard(models.TransientModel):
is_first_line = True is_first_line = True
for line in order.lines: 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 continue
if old_format and not is_first_line: 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(' ', '') company_ident = (company.company_registry or company.name or '').upper().replace(' ', '')
# Max length logic # Max length logic
# For old_format: len("POS__YYMMDD_to_YYMMDD_OLD.xlsx") = 30 chars -> leaves 10 chars for company_ident # base: len("POS__YYMMDD_to_YYMMDD.xlsx") = 26 chars -> leaves 14 chars
# For new_format: len("POS__YYMMDD_to_YYMMDD.xlsx") = 26 chars -> leaves 14 chars for company_ident company_len = 14
company_len = 10 if old_format else 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] company_ident = company_ident[:company_len]
start_str = self.start_date.strftime('%y%m%d') start_str = self.start_date.strftime('%y%m%d')
end_str = self.end_date.strftime('%y%m%d') end_str = self.end_date.strftime('%y%m%d')
if old_format: if export_all:
file_name = f"POS_{company_ident}_{start_str}_to_{end_str}_OLD.xlsx" 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: else:
file_name = f"POS_{company_ident}_{start_str}_to_{end_str}.xlsx" file_name = f"POS_{company_ident}_{start_str}_to_{end_str}.xlsx"

View File

@ -19,6 +19,7 @@
<footer> <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_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_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"/> <button string="Cancel" class="btn-secondary" special="cancel" data-hotkey="z"/>
</footer> </footer>
</form> </form>