def worksheet_setup_a4(worksheet, title1, title2, add_print_title=True): worksheet.title = format_worksheet_title(title1) worksheet.page_setup.paperSize = worksheet.PAPERSIZE_A4 worksheet.page_setup.fitToPage = True worksheet.page_setup.fitToHeight = 0 worksheet.page_setup.fitToWidth = 1 worksheet.print_gridlines = True if add_print_title: worksheet.add_print_title(1, rows_or_cols='rows') worksheet.freeze_panes = 'A2' worksheet.header_footer.left_header.text = Site.objects.get_current().name worksheet.header_footer.left_footer.text = "{}".format(title2) worksheet.header_footer.center_footer.text = "{}".format(title1) worksheet.header_footer.right_footer.text = 'Page &[Page]/&[Pages]' orders_responsible = Staff.get_or_create_order_responsible() invoices_responsible = Staff.get_or_create_invoice_responsible() s1 = EMPTY_STRING if orders_responsible: c = orders_responsible.customer_responsible if c is not None: s1 = "{}: {}, {}".format(_("Orders"), c.long_basket_name, c.phone1) s2 = EMPTY_STRING if invoices_responsible: c = invoices_responsible.customer_responsible if c is not None: s2 = "{}: {}, {}".format(_("Invoices"), c.long_basket_name, c.phone1) separator = chr(10) + " " worksheet.header_footer.right_header.text = separator.join((s1, s2)) return worksheet
def worksheet_setup_a4(worksheet, title1, title2, add_print_title=True): worksheet.title = format_worksheet_title(title1) worksheet.page_setup.paperSize = worksheet.PAPERSIZE_A4 worksheet.page_setup.fitToPage = True worksheet.page_setup.fitToHeight = 0 worksheet.page_setup.fitToWidth = 1 worksheet.print_gridlines = True if add_print_title: worksheet.add_print_title(1, rows_or_cols='rows') worksheet.freeze_panes = 'A2' worksheet.header_footer.left_header.text = Site.objects.get_current().name worksheet.header_footer.left_footer.text = "{}".format(title2) worksheet.header_footer.center_footer.text = "{}".format(title1) worksheet.header_footer.right_footer.text = 'Page &[Page]/&[Pages]' orders_responsible = Staff.get_or_create_order_responsible() invoices_responsible = Staff.get_or_create_invoice_responsible() s1 = EMPTY_STRING if orders_responsible: c = orders_responsible.customer_responsible if c is not None: s1 = "{}: {}{}".format(_("Orders"), c.long_basket_name, c.get_phone1(prefix=", ")) s2 = EMPTY_STRING if invoices_responsible: c = invoices_responsible.customer_responsible if c is not None: s2 = "{}: {}{}".format(_("Invoices"), c.long_basket_name, c.get_phone1(prefix=", ")) separator = chr(10) + " " worksheet.header_footer.right_header.text = separator.join((s1, s2)) return worksheet
def worksheet_setup_a4(worksheet, title1, title2, add_print_title=True): worksheet.title = format_worksheet_title(title1) worksheet.page_setup.paperSize = worksheet.PAPERSIZE_A4 worksheet.page_setup.fitToPage = True worksheet.page_setup.fitToHeight = 0 worksheet.page_setup.fitToWidth = 1 worksheet.print_gridlines = True if add_print_title: worksheet.add_print_title(1, rows_or_cols="rows") worksheet.freeze_panes = "A2" worksheet.header_footer.left_header.text = Site.objects.get_current().name worksheet.header_footer.left_footer.text = "{}".format(title2) worksheet.header_footer.center_footer.text = "{}".format(title1) worksheet.header_footer.right_footer.text = "Page &[Page]/&[Pages]" order_responsible = Staff.get_or_create_order_responsible() invoice_responsible = Staff.get_or_create_invoice_responsible() separator = chr(10) + " " worksheet.header_footer.right_header.text = separator.join( (order_responsible["signature"], invoice_responsible["signature"]) ) return worksheet
def init_repanier(cls): from repanier.const import DECIMAL_ONE, PERMANENCE_NAME_PERMANENCE, CURRENCY_EUR from repanier.models.producer import Producer from repanier.models.bankaccount import BankAccount from repanier.models.staff import Staff from repanier.models.customer import Customer # Create the configuration record managed via the admin UI config = Configuration.objects.filter(id=DECIMAL_ONE).first() if config is not None: return config group_name = settings.REPANIER_SETTINGS_GROUP_NAME site = Site.objects.get_current() if site is not None: site.name = group_name site.domain = group_name site.save() config = Configuration.objects.create( group_name=group_name, name=PERMANENCE_NAME_PERMANENCE, bank_account="BE99 9999 9999 9999", currency=CURRENCY_EUR) config.init_email() config.save() # Create firsts users Producer.get_or_create_group() customer_buyinggroup = Customer.get_or_create_group() very_first_customer = Customer.get_or_create_the_very_first_customer() BankAccount.open_account(customer_buyinggroup=customer_buyinggroup, very_first_customer=very_first_customer) coordinator = Staff.get_or_create_any_coordinator() Staff.get_or_create_order_responsible() Staff.get_or_create_invoice_responsible() # Create and publish first web page if not coordinator.is_webmaster: # This should not be the case... return from cms.models import StaticPlaceholder from cms.constants import X_FRAME_OPTIONS_DENY from cms import api page = api.create_page(title=_("Home"), soft_root=False, template=settings.CMS_TEMPLATE_HOME, language=settings.LANGUAGE_CODE, published=True, parent=None, xframe_options=X_FRAME_OPTIONS_DENY, in_navigation=True) try: # New in CMS 3.5 page.set_as_homepage() except: pass placeholder = page.placeholders.get(slot="home-hero") api.add_plugin(placeholder=placeholder, plugin_type='TextPlugin', language=settings.LANGUAGE_CODE, body=settings.CMS_TEMPLATE_HOME_HERO) placeholder = page.placeholders.get(slot="home-col-1") api.add_plugin(placeholder=placeholder, plugin_type='TextPlugin', language=settings.LANGUAGE_CODE, body=settings.CMS_TEMPLATE_HOME_COL_1) placeholder = page.placeholders.get(slot="home-col-2") api.add_plugin(placeholder=placeholder, plugin_type='TextPlugin', language=settings.LANGUAGE_CODE, body=settings.CMS_TEMPLATE_HOME_COL_2) placeholder = page.placeholders.get(slot="home-col-3") api.add_plugin(placeholder=placeholder, plugin_type='TextPlugin', language=settings.LANGUAGE_CODE, body=settings.CMS_TEMPLATE_HOME_COL_3) static_placeholder = StaticPlaceholder(code="footer", # site_id=1 ) static_placeholder.save() api.add_plugin(placeholder=static_placeholder.draft, plugin_type='TextPlugin', language=settings.LANGUAGE_CODE, body='hello world footer') static_placeholder.publish(request=None, language=settings.LANGUAGE_CODE, force=True) api.publish_page(page=page, user=coordinator.user, language=settings.LANGUAGE_CODE) return config
def init_repanier(cls): from repanier.const import DECIMAL_ONE, PERMANENCE_NAME_PERMANENCE, CURRENCY_EUR from repanier.models.producer import Producer from repanier.models.bankaccount import BankAccount from repanier.models.staff import Staff from repanier.models.customer import Customer from repanier.models.lut import LUT_DepartmentForCustomer logger.debug("######## start of init_repanier") # Create the configuration record managed via the admin UI config = Configuration.objects.filter(id=DECIMAL_ONE).first() if config is not None: return config site = Site.objects.get_current() if site is not None: site.name = settings.REPANIER_SETTINGS_GROUP_NAME site.domain = settings.ALLOWED_HOSTS[0] site.save() config = Configuration.objects.create( group_name=settings.REPANIER_SETTINGS_GROUP_NAME, name=PERMANENCE_NAME_PERMANENCE, bank_account="BE99 9999 9999 9999", currency=CURRENCY_EUR, ) config.init_email() config.save() # Create firsts users Producer.get_or_create_group() customer_buyinggroup = Customer.get_or_create_group() very_first_customer = Customer.get_or_create_the_very_first_customer() BankAccount.open_account( customer_buyinggroup=customer_buyinggroup, very_first_customer=very_first_customer, ) very_first_customer = Customer.get_or_create_the_very_first_customer() coordinator = Staff.get_or_create_any_coordinator() Staff.get_or_create_order_responsible() Staff.get_or_create_invoice_responsible() # Create and publish first web page if not coordinator.is_webmaster: # This should not be the case... return from cms.models import StaticPlaceholder from cms.constants import X_FRAME_OPTIONS_DENY from cms import api page = api.create_page( title=_("Home"), soft_root=False, template=settings.CMS_TEMPLATE_HOME, language=settings.LANGUAGE_CODE, published=True, parent=None, xframe_options=X_FRAME_OPTIONS_DENY, in_navigation=True, ) try: # New in CMS 3.5 page.set_as_homepage() except: pass placeholder = page.placeholders.get(slot="home-hero") api.add_plugin( placeholder=placeholder, plugin_type="TextPlugin", language=settings.LANGUAGE_CODE, body=settings.CMS_TEMPLATE_HOME_HERO, ) static_placeholder = StaticPlaceholder( code="footer", # site_id=1 ) static_placeholder.save() api.add_plugin( placeholder=static_placeholder.draft, plugin_type="TextPlugin", language=settings.LANGUAGE_CODE, body="hello world footer", ) static_placeholder.publish( request=None, language=settings.LANGUAGE_CODE, force=True ) api.publish_page( page=page, user=coordinator.customer_responsible.user, language=settings.LANGUAGE_CODE, ) if LUT_DepartmentForCustomer.objects.count() == 0: # Generate a template of LUT_DepartmentForCustomer parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Vegetable")) LUT_DepartmentForCustomer.objects.create( short_name=_("Basket of vegetables"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Salad"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Tomato"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Potato"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Green"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Cabbage"), parent=parent ) parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Fruit")) LUT_DepartmentForCustomer.objects.create( short_name=_("Basket of fruits"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Apple"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Pear"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Plum"), parent=parent ) parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Bakery")) LUT_DepartmentForCustomer.objects.create( short_name=_("Flour"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Bread"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Pastry"), parent=parent ) parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Butchery")) LUT_DepartmentForCustomer.objects.create( short_name=_("Delicatessen"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Chicken"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Pork"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Beef"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Beef and pork"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Veal"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Lamb"), parent=parent ) parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Grocery")) LUT_DepartmentForCustomer.objects.create( short_name=_("Takeaway"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Pasta"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Chocolate"), parent=parent ) LUT_DepartmentForCustomer.objects.create(short_name=_("Oil"), parent=parent) LUT_DepartmentForCustomer.objects.create(short_name=_("Egg"), parent=parent) LUT_DepartmentForCustomer.objects.create(short_name=_("Jam"), parent=parent) LUT_DepartmentForCustomer.objects.create( short_name=_("Cookie"), parent=parent ) parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Creamery")) LUT_DepartmentForCustomer.objects.create( short_name=_("Dairy"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Cow cheese"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Goat cheese"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Sheep cheese"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Mixed cheese"), parent=parent ) parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Icecream")) LUT_DepartmentForCustomer.objects.create( short_name=_("Cup of icecream"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Icecream per liter"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Icecream in frisco"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Icecream cake"), parent=parent ) parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Sorbet")) LUT_DepartmentForCustomer.objects.create( short_name=_("Cup of sorbet"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Sorbet per liter"), parent=parent ) parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Drink")) LUT_DepartmentForCustomer.objects.create( short_name=_("Juice"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Coffee"), parent=parent ) LUT_DepartmentForCustomer.objects.create(short_name=_("Tea"), parent=parent) LUT_DepartmentForCustomer.objects.create( short_name=_("Herbal tea"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Wine"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Aperitif"), parent=parent ) LUT_DepartmentForCustomer.objects.create( short_name=_("Liqueurs"), parent=parent ) parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Hygiene")) parent = LUT_DepartmentForCustomer.objects.create(short_name=_("Deposit")) parent = LUT_DepartmentForCustomer.objects.create( short_name=_("Subscription") ) logger.debug("######## end of init_repanier") return config
def send_invoices(self, request, permanence_id, permanence=None): if "apply" in request.POST: t = threading.Thread(target=email_invoice.send_invoice, args=(permanence_id, )) t.start() user_message = _("The invoices are being send.") user_message_level = messages.INFO self.message_user(request, user_message, user_message_level) return HttpResponseRedirect(self.get_redirect_to_change_list_url()) template_invoice_customer_mail = [] template_invoice_producer_mail = [] invoice_customer_email_will_be_sent, invoice_customer_email_will_be_sent_to = RepanierEmail.send_email_to_who( is_email_send=repanier.apps. REPANIER_SETTINGS_SEND_INVOICE_MAIL_TO_CUSTOMER) invoice_producer_email_will_be_sent, invoice_producer_email_will_be_sent_to = RepanierEmail.send_email_to_who( is_email_send=repanier.apps. REPANIER_SETTINGS_SEND_INVOICE_MAIL_TO_PRODUCER) if invoice_customer_email_will_be_sent or invoice_producer_email_will_be_sent: cur_language = translation.get_language() for language in settings.PARLER_LANGUAGES[settings.SITE_ID]: language_code = language["code"] translation.activate(language_code) invoice_responsible = Staff.get_or_create_invoice_responsible() if invoice_customer_email_will_be_sent: with switch_language( repanier.apps.REPANIER_SETTINGS_CONFIG, language_code): template = Template( repanier.apps.REPANIER_SETTINGS_CONFIG. invoice_customer_mail) with switch_language(permanence, language_code): invoice_description = permanence.safe_translation_getter( "invoice_description", any_language=True, default=EMPTY_STRING, ) # TODO : Align on tools.payment_message customer_order_amount = _( "The amount of your order is %(amount)s.") % { "amount": RepanierMoney(123.45) } customer_last_balance = _( "The balance of your account as of %(date)s is %(balance)s." ) % { "date": timezone.now().strftime(settings.DJANGO_SETTINGS_DATE), "balance": RepanierMoney(123.45), } bank_account_number = repanier.apps.REPANIER_SETTINGS_BANK_ACCOUNT if bank_account_number is not None: group_name = settings.REPANIER_SETTINGS_GROUP_NAME if permanence.short_name: communication = "{} ({})".format( _("Short name"), permanence.short_name) else: communication = _("Short name") customer_payment_needed = '<font color="#bd0926">{}</font>'.format( _("Please pay a provision of %(payment)s to the bank account %(name)s %(number)s with communication %(communication)s." ) % { "payment": RepanierMoney(123.45), "name": group_name, "number": bank_account_number, "communication": communication, }) else: customer_payment_needed = EMPTY_STRING context = TemplateContext({ "name": _("Long name"), "long_basket_name": _("Long name"), "basket_name": _("Short name"), "short_basket_name": _("Short name"), "permanence_link": mark_safe('<a href="#">{}</a>'.format(permanence)), "last_balance_link": mark_safe('<a href="#">{}</a>'.format( customer_last_balance)), "last_balance": customer_last_balance, "order_amount": mark_safe(customer_order_amount), "payment_needed": mark_safe(customer_payment_needed), "invoice_description": mark_safe(invoice_description), "signature": invoice_responsible["html_signature"], }) template_invoice_customer_mail.append(language_code) template_invoice_customer_mail.append( template.render(context)) if invoice_producer_email_will_be_sent: with switch_language( repanier.apps.REPANIER_SETTINGS_CONFIG, language_code): template = Template( repanier.apps.REPANIER_SETTINGS_CONFIG. invoice_producer_mail) context = TemplateContext({ "name": _("Long name"), "long_profile_name": _("Long name"), "permanence_link": mark_safe('<a href="#">{}</a>'.format(permanence)), "signature": invoice_responsible["html_signature"], }) template_invoice_producer_mail.append(language_code) template_invoice_producer_mail.append( template.render(context)) translation.activate(cur_language) form = InvoiceOrderForm( initial={ "template_invoice_customer_mail": mark_safe("<br>==============<br>".join( template_invoice_customer_mail)), "template_invoice_producer_mail": mark_safe("<br>==============<br>".join( template_invoice_producer_mail)), }) template_name = get_repanier_template_name( "admin/confirm_send_invoice.html") return render( request, template_name, { **self.admin_site.each_context(request), "action_checkbox_name": admin.ACTION_CHECKBOX_NAME, "action": "send_invoices", "permanence": permanence, "form": form, "invoice_customer_email_will_be_sent_to": invoice_customer_email_will_be_sent_to, "invoice_producer_email_will_be_sent_to": invoice_producer_email_will_be_sent_to, }, )
def send_invoice(permanence_id): from repanier.apps import REPANIER_SETTINGS_SEND_INVOICE_MAIL_TO_PRODUCER, \ REPANIER_SETTINGS_SEND_INVOICE_MAIL_TO_CUSTOMER, \ REPANIER_SETTINGS_CONFIG cur_language = translation.get_language() for language in settings.PARLER_LANGUAGES[settings.SITE_ID]: language_code = language["code"] translation.activate(language_code) permanence = Permanence.objects.get(id=permanence_id) config = REPANIER_SETTINGS_CONFIG invoice_responsible = Staff.get_or_create_invoice_responsible() if REPANIER_SETTINGS_SEND_INVOICE_MAIL_TO_PRODUCER: # To the producer we speak of "payment". # This is the detail of the payment to the producer, i.e. received products for producer in Producer.objects.filter( permanence_id=permanence.id, language=language_code ).order_by('?'): to_email = [] if producer.email: to_email.append(producer.email) if producer.email2: to_email.append(producer.email2) if producer.email3: to_email.append(producer.email3) if to_email: to_email = list(set(to_email + invoice_responsible.get_to_email)) long_profile_name = producer.long_profile_name \ if producer.long_profile_name is not None else producer.short_profile_name if Purchase.objects.filter( permanence_id=permanence.id, producer_id=producer.id ).order_by('?').exists(): invoice_producer_mail = config.safe_translation_getter( 'invoice_producer_mail', any_language=True, default=EMPTY_STRING ) invoice_producer_mail_subject = "{} - {}".format(settings.REPANIER_SETTINGS_GROUP_NAME, permanence) template = Template(invoice_producer_mail) context = TemplateContext({ 'name': long_profile_name, 'long_profile_name': long_profile_name, 'permanence_link': mark_safe( "<a href=\"https://{}{}\">{}</a>".format(settings.ALLOWED_HOSTS[0], reverse('producer_invoice_uuid_view', args=(0, producer.uuid)), permanence)), 'signature': invoice_responsible.get_html_signature }) html_body = template.render(context) email = RepanierEmail( subject=invoice_producer_mail_subject, html_body=html_body, to=to_email ) email.send_email() if REPANIER_SETTINGS_SEND_INVOICE_MAIL_TO_CUSTOMER: # To the customer we speak of "invoice". # This is the detail of the invoice, i.e. sold products invoice_description = permanence.safe_translation_getter( 'invoice_description', any_language=True, default=EMPTY_STRING ) for customer in Customer.objects.filter( customerinvoice__permanence_id=permanence.id, customerinvoice__customer_charged_id=F('customer_id'), represent_this_buyinggroup=False, language=language_code ).order_by('?'): long_basket_name = customer.long_basket_name if customer.long_basket_name is not None else customer.short_basket_name if Purchase.objects.filter( permanence_id=permanence.id, customer_invoice__customer_charged_id=customer.id ).order_by('?').exists(): to_email = [customer.user.email] if customer.email2: to_email.append(customer.email2) to_email = list(set(to_email + invoice_responsible.get_to_email)) invoice_customer_mail = config.safe_translation_getter( 'invoice_customer_mail', any_language=True, default=EMPTY_STRING ) invoice_customer_mail_subject = "{} - {}".format(settings.REPANIER_SETTINGS_GROUP_NAME, permanence) customer_last_balance, _, customer_payment_needed, customer_order_amount = payment_message( customer, permanence) template = Template(invoice_customer_mail) context = TemplateContext({ 'name': long_basket_name, 'long_basket_name': long_basket_name, 'basket_name': customer.short_basket_name, 'short_basket_name': customer.short_basket_name, 'permanence_link': mark_safe( "<a href=\"https://{}{}\">{}</a>".format(settings.ALLOWED_HOSTS[0], reverse('order_view', args=(permanence.id,)), permanence)), 'last_balance_link': mark_safe("<a href=\"https://{}{}\">{}</a>".format( settings.ALLOWED_HOSTS[0], reverse('customer_invoice_view', args=(0,)), customer_last_balance)), 'last_balance': mark_safe(customer_last_balance), 'order_amount': mark_safe(customer_order_amount), 'payment_needed': mark_safe(customer_payment_needed), 'invoice_description': mark_safe(invoice_description), 'signature': invoice_responsible.get_html_signature }) html_body = template.render(context) email = RepanierEmail( subject=invoice_customer_mail_subject, html_body=html_body, to=to_email, show_customer_may_unsubscribe=True ) email.send_email() translation.activate(cur_language)
def send_invoice(permanence_id): from repanier.apps import REPANIER_SETTINGS_SEND_INVOICE_MAIL_TO_PRODUCER, \ REPANIER_SETTINGS_SEND_INVOICE_MAIL_TO_CUSTOMER, \ REPANIER_SETTINGS_CONFIG cur_language = translation.get_language() for language in settings.PARLER_LANGUAGES[settings.SITE_ID]: language_code = language["code"] translation.activate(language_code) permanence = Permanence.objects.get(id=permanence_id) config = REPANIER_SETTINGS_CONFIG invoice_responsible = Staff.get_or_create_invoice_responsible() if REPANIER_SETTINGS_SEND_INVOICE_MAIL_TO_PRODUCER: # To the producer we speak of "payment". # This is the detail of the payment to the producer, i.e. received products for producer in Producer.objects.filter( permanence_id=permanence.id, language=language_code).order_by('?'): to_email = [] if producer.email: to_email.append(producer.email) if producer.email2: to_email.append(producer.email2) if producer.email3: to_email.append(producer.email3) if to_email: to_email = list( set(to_email + invoice_responsible["to_email"])) long_profile_name = producer.long_profile_name \ if producer.long_profile_name is not None else producer.short_profile_name if Purchase.objects.filter( permanence_id=permanence.id, producer_id=producer.id).order_by('?').exists(): invoice_producer_mail = config.safe_translation_getter( 'invoice_producer_mail', any_language=True, default=EMPTY_STRING) invoice_producer_mail_subject = "{} - {}".format( settings.REPANIER_SETTINGS_GROUP_NAME, permanence) template = Template(invoice_producer_mail) context = TemplateContext({ 'name': long_profile_name, 'long_profile_name': long_profile_name, 'permanence_link': mark_safe("<a href=\"https://{}{}\">{}</a>".format( settings.ALLOWED_HOSTS[0], reverse('producer_invoice_uuid_view', args=(0, producer.uuid)), permanence)), 'signature': invoice_responsible["html_signature"] }) html_body = template.render(context) email = RepanierEmail( subject=invoice_producer_mail_subject, html_body=html_body, to=to_email) email.send_email() if REPANIER_SETTINGS_SEND_INVOICE_MAIL_TO_CUSTOMER: # To the customer we speak of "invoice". # This is the detail of the invoice, i.e. sold products invoice_description = permanence.safe_translation_getter( 'invoice_description', any_language=True, default=EMPTY_STRING) for customer in Customer.objects.filter( customerinvoice__permanence_id=permanence.id, customerinvoice__customer_charged_id=F('customer_id'), represent_this_buyinggroup=False, language=language_code).order_by('?'): long_basket_name = customer.long_basket_name if customer.long_basket_name is not None else customer.short_basket_name if Purchase.objects.filter( permanence_id=permanence.id, customer_invoice__customer_charged_id=customer.id ).order_by('?').exists(): to_email = [customer.user.email] if customer.email2: to_email.append(customer.email2) to_email = list( set(to_email + invoice_responsible["to_email"])) invoice_customer_mail = config.safe_translation_getter( 'invoice_customer_mail', any_language=True, default=EMPTY_STRING) invoice_customer_mail_subject = "{} - {}".format( settings.REPANIER_SETTINGS_GROUP_NAME, permanence) customer_last_balance, _, customer_payment_needed, customer_order_amount = payment_message( customer, permanence) template = Template(invoice_customer_mail) context = TemplateContext({ 'name': long_basket_name, 'long_basket_name': long_basket_name, 'basket_name': customer.short_basket_name, 'short_basket_name': customer.short_basket_name, 'permanence_link': mark_safe("<a href=\"https://{}{}\">{}</a>".format( settings.ALLOWED_HOSTS[0], reverse('order_view', args=(permanence.id, )), permanence)), 'last_balance_link': mark_safe("<a href=\"https://{}{}\">{}</a>".format( settings.ALLOWED_HOSTS[0], reverse('customer_invoice_view', args=(0, )), customer_last_balance)), 'last_balance': mark_safe(customer_last_balance), 'order_amount': mark_safe(customer_order_amount), 'payment_needed': mark_safe(customer_payment_needed), 'invoice_description': mark_safe(invoice_description), 'signature': invoice_responsible["html_signature"] }) html_body = template.render(context) email = RepanierEmail( subject=invoice_customer_mail_subject, html_body=html_body, to=to_email, show_customer_may_unsubscribe=True) email.send_email() translation.activate(cur_language)
def send_invoices(self, request, permanence_qs): if 'cancel' in request.POST: user_message = _("Action canceled by the user.") user_message_level = messages.INFO self.message_user(request, user_message, user_message_level) return permanence = permanence_qs.first() if permanence.status != PERMANENCE_INVOICED: user_message = _("The status of %(permanence)s prohibit you to perform this action.") % { 'permanence': permanence} user_message_level = messages.ERROR self.message_user(request, user_message, user_message_level) return template = Template(repanier.apps.REPANIER_SETTINGS_CONFIG.invoice_customer_mail) invoice_description = permanence.safe_translation_getter( 'invoice_description', any_language=True, default=EMPTY_STRING ) staff = Staff.get_or_create_invoice_responsible() # TODO : Align on tools.payment_message customer_order_amount = \ _('The amount of your order is %(amount)s.') % { 'amount': RepanierMoney(123.45) } customer_last_balance = \ _('The balance of your account as of %(date)s is %(balance)s.') % { 'date': timezone.now().strftime(settings.DJANGO_SETTINGS_DATE), 'balance': RepanierMoney(123.45) } bank_account_number = repanier.apps.REPANIER_SETTINGS_BANK_ACCOUNT if bank_account_number is not None: group_name = settings.REPANIER_SETTINGS_GROUP_NAME if permanence.short_name: communication = "{} ({})".format(_('Short name'), permanence.short_name) else: communication = _('Short name') customer_payment_needed = "<font color=\"#bd0926\">{}</font>".format( _( 'Please pay a provision of %(payment)s to the bank account %(name)s %(number)s with communication %(communication)s.') % { 'payment': RepanierMoney(123.45), 'name': group_name, 'number': bank_account_number, 'communication': communication } ) else: customer_payment_needed = EMPTY_STRING context = TemplateContext({ 'name': _('Long name'), 'long_basket_name': _('Long name'), 'basket_name': _('Short name'), 'short_basket_name': _('Short name'), 'permanence_link': mark_safe("<a href=\"#\">{}</a>".format(permanence)), 'last_balance_link': mark_safe("<a href=\"#\">{}</a>".format(customer_last_balance)), 'last_balance': customer_last_balance, 'order_amount': mark_safe(customer_order_amount), 'payment_needed': mark_safe(customer_payment_needed), 'invoice_description': mark_safe(invoice_description), 'signature': staff.get_html_signature, }) template_invoice_customer_mail = template.render(context) invoice_customer_email_will_be_sent, invoice_customer_email_will_be_sent_to = RepanierEmail.send_email_to_who( is_email_send=repanier.apps.REPANIER_SETTINGS_SEND_INVOICE_MAIL_TO_CUSTOMER ) template = Template(repanier.apps.REPANIER_SETTINGS_CONFIG.invoice_producer_mail) context = TemplateContext({ 'name': _('Long name'), 'long_profile_name': _('Long name'), 'permanence_link': mark_safe("<a href=\"#\">{}</a>".format(permanence)), 'signature': staff.get_html_signature, }) template_invoice_producer_mail = template.render(context) invoice_producer_email_will_be_sent, invoice_producer_email_will_be_sent_to = RepanierEmail.send_email_to_who( is_email_send=repanier.apps.REPANIER_SETTINGS_SEND_INVOICE_MAIL_TO_PRODUCER ) if 'apply' in request.POST: form = InvoiceOrderForm(request.POST) if form.is_valid(): t = threading.Thread(target=email_invoice.send_invoice, args=(permanence.id,)) t.start() user_message = _("Emails containing the invoices will be send to the customers and the producers.") user_message_level = messages.INFO self.message_user(request, user_message, user_message_level) return HttpResponseRedirect(request.get_full_path()) else: form = InvoiceOrderForm( initial={ 'template_invoice_customer_mail': mark_safe(template_invoice_customer_mail), 'template_invoice_producer_mail': mark_safe(template_invoice_producer_mail), } ) template_name = get_repanier_template_name( 'repanier/confirm_admin_send_invoice.html' ) return render( request, template_name, { 'sub_title': _("Please, confirm the action : send invoices"), 'action_checkbox_name': admin.ACTION_CHECKBOX_NAME, 'action': 'send_invoices', 'permanence': permanence, 'form': form, 'invoice_customer_email_will_be_sent': invoice_customer_email_will_be_sent, 'invoice_customer_email_will_be_sent_to': invoice_customer_email_will_be_sent_to, 'invoice_producer_email_will_be_sent': invoice_producer_email_will_be_sent, 'invoice_producer_email_will_be_sent_to': invoice_producer_email_will_be_sent_to })
def send_invoices(self, request, permanence_qs): if 'cancel' in request.POST: user_message = _("Action canceled by the user.") user_message_level = messages.INFO self.message_user(request, user_message, user_message_level) return permanence = permanence_qs.first() if permanence.status != PERMANENCE_INVOICED: user_message = _("The status of %(permanence)s prohibit you to perform this action.") % { 'permanence': permanence} user_message_level = messages.ERROR self.message_user(request, user_message, user_message_level) return template = Template(repanier.apps.REPANIER_SETTINGS_CONFIG.invoice_customer_mail) invoice_description = permanence.safe_translation_getter( 'invoice_description', any_language=True, default=EMPTY_STRING ) staff = Staff.get_or_create_invoice_responsible() # TODO : Align on tools.payment_message customer_order_amount = \ _('The amount of your order is %(amount)s.') % { 'amount': RepanierMoney(123.45) } customer_last_balance = \ _('The balance of your account as of %(date)s is %(balance)s.') % { 'date': timezone.now().strftime(settings.DJANGO_SETTINGS_DATE), 'balance': RepanierMoney(123.45) } customer_payment_needed = "{} {} {} ({}) {} \"{}\".".format( _('Please pay'), RepanierMoney(123.45), _('to the bank account number'), repanier.apps.REPANIER_SETTINGS_BANK_ACCOUNT, _('with communication'), _('Short name')) context = TemplateContext({ 'name': _('Long name'), 'long_basket_name': _('Long name'), 'basket_name': _('Short name'), 'short_basket_name': _('Short name'), 'permanence_link': mark_safe("<a href=\"#\">{}</a>".format(permanence)), 'last_balance_link': mark_safe("<a href=\"#\">{}</a>".format(customer_last_balance)), 'last_balance': customer_last_balance, 'order_amount': mark_safe(customer_order_amount), 'payment_needed': mark_safe(customer_payment_needed), 'invoice_description': mark_safe(invoice_description), 'signature': staff.get_html_signature, }) template_invoice_customer_mail = template.render(context) invoice_customer_email_will_be_sent, invoice_customer_email_will_be_sent_to = send_email_to_who( repanier.apps.REPANIER_SETTINGS_SEND_INVOICE_MAIL_TO_CUSTOMER ) template = Template(repanier.apps.REPANIER_SETTINGS_CONFIG.invoice_producer_mail) context = TemplateContext({ 'name': _('Long name'), 'long_profile_name': _('Long name'), 'permanence_link': mark_safe("<a href=\"#\">{}</a>".format(permanence)), 'signature': staff.get_html_signature, }) template_invoice_producer_mail = template.render(context) invoice_producer_email_will_be_sent, invoice_producer_email_will_be_sent_to = send_email_to_who( repanier.apps.REPANIER_SETTINGS_SEND_INVOICE_MAIL_TO_PRODUCER ) if 'apply' in request.POST: form = InvoiceOrderForm(request.POST) if form.is_valid(): t = threading.Thread(target=email_invoice.send_invoice, args=(permanence.id,)) t.start() user_message = _("Emails containing the invoices will be send to the customers and the producers.") user_message_level = messages.INFO self.message_user(request, user_message, user_message_level) return HttpResponseRedirect(request.get_full_path()) else: form = InvoiceOrderForm( initial={ 'template_invoice_customer_mail': mark_safe(template_invoice_customer_mail), 'template_invoice_producer_mail': mark_safe(template_invoice_producer_mail), } ) return render( request, 'repanier/confirm_admin_send_invoice.html', { 'sub_title': _("Please, confirm the action : send invoices"), 'action_checkbox_name': admin.ACTION_CHECKBOX_NAME, 'action': 'send_invoices', 'permanence': permanence, 'form': form, 'invoice_customer_email_will_be_sent': invoice_customer_email_will_be_sent, 'invoice_customer_email_will_be_sent_to': invoice_customer_email_will_be_sent_to, 'invoice_producer_email_will_be_sent': invoice_producer_email_will_be_sent, 'invoice_producer_email_will_be_sent_to': invoice_producer_email_will_be_sent_to })
def send_invoices(self, request, permanence_qs): if "cancel" in request.POST: user_message = _("Action canceled by the user.") user_message_level = messages.INFO self.message_user(request, user_message, user_message_level) return permanence = permanence_qs.first() if permanence.status != PERMANENCE_INVOICED: user_message = _( "The status of %(permanence)s prohibit you to perform this action." ) % { "permanence": permanence } user_message_level = messages.ERROR self.message_user(request, user_message, user_message_level) return template = Template( repanier.apps.REPANIER_SETTINGS_CONFIG.invoice_customer_mail) invoice_description = permanence.safe_translation_getter( "invoice_description", any_language=True, default=EMPTY_STRING) staff = Staff.get_or_create_invoice_responsible() # TODO : Align on tools.payment_message customer_order_amount = _( "The amount of your order is %(amount)s.") % { "amount": RepanierMoney(123.45) } customer_last_balance = _( "The balance of your account as of %(date)s is %(balance)s.") % { "date": timezone.now().strftime(settings.DJANGO_SETTINGS_DATE), "balance": RepanierMoney(123.45), } bank_account_number = repanier.apps.REPANIER_SETTINGS_BANK_ACCOUNT if bank_account_number is not None: group_name = settings.REPANIER_SETTINGS_GROUP_NAME if permanence.short_name: communication = "{} ({})".format(_("Short name"), permanence.short_name) else: communication = _("Short name") customer_payment_needed = '<font color="#bd0926">{}</font>'.format( _("Please pay a provision of %(payment)s to the bank account %(name)s %(number)s with communication %(communication)s." ) % { "payment": RepanierMoney(123.45), "name": group_name, "number": bank_account_number, "communication": communication, }) else: customer_payment_needed = EMPTY_STRING context = TemplateContext({ "name": _("Long name"), "long_basket_name": _("Long name"), "basket_name": _("Short name"), "short_basket_name": _("Short name"), "permanence_link": mark_safe('<a href="#">{}</a>'.format(permanence)), "last_balance_link": mark_safe('<a href="#">{}</a>'.format(customer_last_balance)), "last_balance": customer_last_balance, "order_amount": mark_safe(customer_order_amount), "payment_needed": mark_safe(customer_payment_needed), "invoice_description": mark_safe(invoice_description), "signature": staff.get_html_signature, }) template_invoice_customer_mail = template.render(context) invoice_customer_email_will_be_sent, invoice_customer_email_will_be_sent_to = RepanierEmail.send_email_to_who( is_email_send=repanier.apps. REPANIER_SETTINGS_SEND_INVOICE_MAIL_TO_CUSTOMER) template = Template( repanier.apps.REPANIER_SETTINGS_CONFIG.invoice_producer_mail) context = TemplateContext({ "name": _("Long name"), "long_profile_name": _("Long name"), "permanence_link": mark_safe('<a href="#">{}</a>'.format(permanence)), "signature": staff.get_html_signature, }) template_invoice_producer_mail = template.render(context) invoice_producer_email_will_be_sent, invoice_producer_email_will_be_sent_to = RepanierEmail.send_email_to_who( is_email_send=repanier.apps. REPANIER_SETTINGS_SEND_INVOICE_MAIL_TO_PRODUCER) if "apply" in request.POST: form = InvoiceOrderForm(request.POST) if form.is_valid(): t = threading.Thread(target=email_invoice.send_invoice, args=(permanence.id, )) t.start() user_message = _( "Emails containing the invoices will be send to the customers and the producers." ) user_message_level = messages.INFO self.message_user(request, user_message, user_message_level) return HttpResponseRedirect(request.get_full_path()) else: form = InvoiceOrderForm( initial={ "template_invoice_customer_mail": mark_safe(template_invoice_customer_mail), "template_invoice_producer_mail": mark_safe(template_invoice_producer_mail), }) template_name = get_repanier_template_name( "confirm_admin_send_invoice.html") return render( request, template_name, { "sub_title": _("Please, confirm the action : send invoices"), "action_checkbox_name": admin.ACTION_CHECKBOX_NAME, "action": "send_invoices", "permanence": permanence, "form": form, "invoice_customer_email_will_be_sent": invoice_customer_email_will_be_sent, "invoice_customer_email_will_be_sent_to": invoice_customer_email_will_be_sent_to, "invoice_producer_email_will_be_sent": invoice_producer_email_will_be_sent, "invoice_producer_email_will_be_sent_to": invoice_producer_email_will_be_sent_to, }, )
def init_repanier(cls): from repanier.const import DECIMAL_ONE, PERMANENCE_NAME_PERMANENCE, CURRENCY_EUR from repanier.models.producer import Producer from repanier.models.bankaccount import BankAccount from repanier.models.staff import Staff from repanier.models.customer import Customer # Create the configuration record managed via the admin UI config = Configuration.objects.filter(id=DECIMAL_ONE).first() if config is not None: return config site = Site.objects.get_current() if site is not None: site.name = settings.REPANIER_SETTINGS_GROUP_NAME site.domain = settings.ALLOWED_HOSTS[0] site.save() config = Configuration.objects.create( group_name=settings.REPANIER_SETTINGS_GROUP_NAME, name=PERMANENCE_NAME_PERMANENCE, bank_account="BE99 9999 9999 9999", currency=CURRENCY_EUR ) config.init_email() config.save() # Create firsts users Producer.get_or_create_group() customer_buyinggroup = Customer.get_or_create_group() very_first_customer = Customer.get_or_create_the_very_first_customer() BankAccount.open_account( customer_buyinggroup=customer_buyinggroup, very_first_customer=very_first_customer ) coordinator = Staff.get_or_create_any_coordinator() Staff.get_or_create_order_responsible() Staff.get_or_create_invoice_responsible() # Create and publish first web page if not coordinator.is_webmaster: # This should not be the case... return from cms.models import StaticPlaceholder from cms.constants import X_FRAME_OPTIONS_DENY from cms import api page = api.create_page( title=_("Home"), soft_root=False, template=settings.CMS_TEMPLATE_HOME, language=settings.LANGUAGE_CODE, published=True, parent=None, xframe_options=X_FRAME_OPTIONS_DENY, in_navigation=True ) try: # New in CMS 3.5 page.set_as_homepage() except: pass placeholder = page.placeholders.get(slot="home-hero") api.add_plugin( placeholder=placeholder, plugin_type='TextPlugin', language=settings.LANGUAGE_CODE, body=settings.CMS_TEMPLATE_HOME_HERO) placeholder = page.placeholders.get(slot="home-col-1") api.add_plugin( placeholder=placeholder, plugin_type='TextPlugin', language=settings.LANGUAGE_CODE, body=settings.CMS_TEMPLATE_HOME_COL_1) placeholder = page.placeholders.get(slot="home-col-2") api.add_plugin( placeholder=placeholder, plugin_type='TextPlugin', language=settings.LANGUAGE_CODE, body=settings.CMS_TEMPLATE_HOME_COL_2) placeholder = page.placeholders.get(slot="home-col-3") api.add_plugin( placeholder=placeholder, plugin_type='TextPlugin', language=settings.LANGUAGE_CODE, body=settings.CMS_TEMPLATE_HOME_COL_3) static_placeholder = StaticPlaceholder( code="footer", # site_id=1 ) static_placeholder.save() api.add_plugin( placeholder=static_placeholder.draft, plugin_type='TextPlugin', language=settings.LANGUAGE_CODE, body='hello world footer' ) static_placeholder.publish( request=None, language=settings.LANGUAGE_CODE, force=True ) api.publish_page( page=page, user=coordinator.user, language=settings.LANGUAGE_CODE) return config