diff --git a/tailbone/templates/batch/inventory/desktop_form.mako b/tailbone/templates/batch/inventory/desktop_form.mako index bc64d498..7e3787ae 100644 --- a/tailbone/templates/batch/inventory/desktop_form.mako +++ b/tailbone/templates/batch/inventory/desktop_form.mako @@ -1,10 +1,11 @@ ## -*- coding: utf-8; -*- -<%inherit file="/base.mako" /> +<%inherit file="/form.mako" /> <%def name="title()">Inventory Form <%def name="extra_javascript()"> ${parent.extra_javascript()} + % if not use_buefy: ${h.javascript_link(request.static_url('tailbone:static/js/numeric.js'))} + % endif <%def name="extra_styles()"> ${parent.extra_styles()} + % if not use_buefy: + % endif - <%def name="context_menu_items()"> + ${parent.context_menu_items()}
  • ${h.link_to("Back to Inventory Batch", url('batch.inventory.view', uuid=batch.uuid))}
  • +<%def name="render_form()"> + % if use_buefy: - + + + + + % else: + ## not buefy + +
    + ${h.form(form.action_url, id='inventory-form')} + ${h.csrf_token(request)} + +
    + +
    + ${h.hidden('product')} +
    ${h.text('upc', autocomplete='off')}
    +
    +

    please ENTER a scancode

    +
    +
    please confirm UPC and provide more details
    +
    product already exists in batch, please confirm count
    +
    pack item scanned, but must count units instead
    +
    +
    +
    + + + + % if allow_cases: +
    + +
    ${h.text('cases', autocomplete='off')}
    +
    + % endif + +
    + +
    ${h.text('units', autocomplete='off')}
    +
    + +
    + ${h.submit('submit', "Submit")} +
    + + ${h.end_form()}
    - - - - - % if allow_cases: -
    - -
    ${h.text('cases', autocomplete='off')}
    -
    % endif + -
    - -
    ${h.text('units', autocomplete='off')}
    -
    -
    - ${h.submit('submit', "Submit")} -
    - - ${h.end_form()} - +${parent.body()} diff --git a/tailbone/templates/form.mako b/tailbone/templates/form.mako index 19e5a4a7..a00b8d97 100644 --- a/tailbone/templates/form.mako +++ b/tailbone/templates/form.mako @@ -57,7 +57,7 @@ <%def name="before_object_helpers()"> <%def name="render_this_page_template()"> - % if form is not Underined: + % if form is not Undefined: ${self.render_form()} % endif ${parent.render_this_page_template()} diff --git a/tailbone/views/batch/core.py b/tailbone/views/batch/core.py index efb61b20..1c35169a 100644 --- a/tailbone/views/batch/core.py +++ b/tailbone/views/batch/core.py @@ -705,9 +705,15 @@ class BatchMasterView(MasterView): if self.rows_creatable and not batch.executed and not batch.complete: permission_prefix = self.get_permission_prefix() if self.request.has_perm('{}.create_row'.format(permission_prefix)): - link = tags.link_to("Create a new {}".format(self.get_row_model_title()), - self.get_action_url('create_row', batch)) - return HTML.tag('p', c=[link]) + url = self.get_action_url('create_row', batch) + if self.get_use_buefy(): + return self.make_buefy_button("New Row", url=url, + is_primary=True, + icon_left='plus') + else: + text = "Create a new {}".format(self.get_row_model_title()) + link = tags.link_to(text, url) + return HTML.tag('p', c=[link]) def make_batch_row_grid_tools(self, batch): if self.get_use_buefy(): diff --git a/tailbone/views/batch/inventory.py b/tailbone/views/batch/inventory.py index f8699725..48bc9267 100644 --- a/tailbone/views/batch/inventory.py +++ b/tailbone/views/batch/inventory.py @@ -2,7 +2,7 @@ ################################################################################ # # Rattail -- Retail Software Framework -# Copyright © 2010-2021 Lance Edgar +# Copyright © 2010-2023 Lance Edgar # # This file is part of Rattail. # @@ -234,40 +234,47 @@ class InventoryBatchView(BatchMasterView): if batch.executed: return self.redirect(self.get_action_url('view', batch)) + use_buefy = self.get_use_buefy() schema = DesktopForm().bind(session=self.Session()) - form = forms.Form(schema=schema, request=self.request) - if form.validate(newstyle=True): + form = forms.Form(schema=schema, request=self.request, use_buefy=use_buefy) + if self.request.method == 'POST': + if form.validate(newstyle=True): - product = self.Session.query(model.Product).get(form.validated['product']) + product = self.Session.query(model.Product).get(form.validated['product']) - row = None - if self.should_aggregate_products(batch): - row = self.find_row_for_product(batch, product) - if row: + row = None + if self.should_aggregate_products(batch): + row = self.find_row_for_product(batch, product) + if row: + row.cases = form.validated['cases'] + row.units = form.validated['units'] + self.handler.refresh_row(row) + + if not row: + row = model.InventoryBatchRow() + row.product = product + row.upc = form.validated['upc'] + row.brand_name = form.validated['brand_name'] + row.description = form.validated['description'] + row.size = form.validated['size'] + row.case_quantity = form.validated['case_quantity'] row.cases = form.validated['cases'] row.units = form.validated['units'] - self.handler.refresh_row(row) + self.handler.capture_current_units(row) + self.handler.add_row(batch, row) - if not row: - row = model.InventoryBatchRow() - row.product = product - row.upc = form.validated['upc'] - row.brand_name = form.validated['brand_name'] - row.description = form.validated['description'] - row.size = form.validated['size'] - row.case_quantity = form.validated['case_quantity'] - row.cases = form.validated['cases'] - row.units = form.validated['units'] - self.handler.capture_current_units(row) - self.handler.add_row(batch, row) + description = make_full_description(form.validated['brand_name'], + form.validated['description'], + form.validated['size']) + self.request.session.flash("{} cases, {} units: {} {}".format( + form.validated['cases'] or 0, form.validated['units'] or 0, + form.validated['upc'].pretty(), description)) + return self.redirect(self.request.current_route_url()) - description = make_full_description(form.validated['brand_name'], - form.validated['description'], - form.validated['size']) - self.request.session.flash("{} cases, {} units: {} {}".format( - form.validated['cases'] or 0, form.validated['units'] or 0, - form.validated['upc'].pretty(), description)) - return self.redirect(self.request.current_route_url()) + else: + dform = form.make_deform_form() + msg = "Form did not validate: {}".format(six.text_type(dform.error)) + self.request.session.flash(msg, 'error') title = self.get_instance_title(batch) return self.render_to_response('desktop_form', {