diff --git a/migrations.py b/migrations.py index d040b46..c4ea3fb 100644 --- a/migrations.py +++ b/migrations.py @@ -256,3 +256,14 @@ async def m017_add_inventory_omit_tags(db: Database): ALTER TABLE tpos.pos ADD inventory_omit_tags TEXT NULL; """ ) + + +async def m018_add_stripe_reader_id(db: Database): + """ + Add Stripe reader id column + """ + await db.execute( + """ + ALTER TABLE tpos.pos ADD stripe_reader_id TEXT NULL; + """ + ) diff --git a/models.py b/models.py index 3b3c155..7d4e956 100644 --- a/models.py +++ b/models.py @@ -65,6 +65,7 @@ class CreateTposData(BaseModel): business_vat_id: str | None fiat_provider: str | None = Field(None) stripe_card_payments: bool = False + stripe_reader_id: str | None = None @validator("tax_default", pre=True, always=True) def default_tax_when_none(cls, v): @@ -97,6 +98,7 @@ class TposClean(BaseModel): business_vat_id: str | None = None fiat_provider: str | None = None stripe_card_payments: bool = False + stripe_reader_id: str | None = None @property def withdraw_maximum(self) -> int: diff --git a/static/js/index.js b/static/js/index.js index 824e327..a88a874 100644 --- a/static/js/index.js +++ b/static/js/index.js @@ -107,7 +107,8 @@ window.app = Vue.createApp({ lnaddress_cut: 2, enable_receipt_print: false, fiat: false, - stripe_card_payments: false + stripe_card_payments: false, + stripe_reader_id: '' }, advanced: { tips: false, @@ -241,7 +242,8 @@ window.app = Vue.createApp({ lnaddress_cut: 2, enable_receipt_print: false, fiat: false, - stripe_card_payments: false + stripe_card_payments: false, + stripe_reader_id: '' } this.formDialog.advanced = {tips: false, otc: false} }, diff --git a/static/js/tpos.js b/static/js/tpos.js index 91ea66a..c1b34c8 100644 --- a/static/js/tpos.js +++ b/static/js/tpos.js @@ -294,6 +294,8 @@ window.app = Vue.createApp({ } quantity = Math.min(quantity, item.quantity_in_stock - inCart) } + const existing = this.cart.get(item.id) + const priceSource = existing || item if (this.cart.has(item.id)) { this.cart.set(item.id, { ...this.cart.get(item.id), @@ -305,11 +307,12 @@ window.app = Vue.createApp({ quantity: quantity }) } - this.total = this.total + this.calculateItemPrice(item, quantity) + this.total = this.total + this.calculateItemPrice(priceSource, quantity) this.cartTaxTotal() }, removeFromCart(item, quantity = 1) { - let item_quantity = this.cart.get(item.id).quantity + const existing = this.cart.get(item.id) + let item_quantity = existing.quantity if (item_quantity == 1 || item_quantity == quantity) { this.cart.delete(item.id) } else { @@ -318,7 +321,55 @@ window.app = Vue.createApp({ quantity: this.cart.get(item.id).quantity - quantity }) } - this.total = this.total - this.calculateItemPrice(item, quantity) + const priceSource = existing || item + this.total = this.total - this.calculateItemPrice(priceSource, quantity) + this.cartTaxTotal() + }, + promptItemPrice(item) { + const cartItem = this.cart.get(item.id) + if (!cartItem) return + this.$q + .dialog({ + title: 'Set price', + message: 'Update item price for this cart line', + prompt: { + model: + this.currency === 'sats' + ? String(cartItem.price) + : cartItem.price.toFixed(2), + type: 'number' + }, + cancel: true + }) + .onOk(val => { + const newPrice = parseFloat(val) + if (isNaN(newPrice) || newPrice < 0) { + Quasar.Notify.create({ + type: 'warning', + message: 'Please enter a valid price.' + }) + return + } + this.updateCartItemPrice(cartItem, newPrice) + }) + }, + updateCartItemPrice(cartItem, newPrice) { + const roundedPrice = + this.currency === 'sats' ? Math.ceil(newPrice) : +newPrice.toFixed(2) + const existing = this.cart.get(cartItem.id) + if (!existing) return + const oldItemTotal = this.calculateItemPrice(existing, existing.quantity) + const updatedItem = { + ...existing, + price: roundedPrice, + formattedPrice: this.formatAmount(roundedPrice, this.currency) + } + this.cart.set(cartItem.id, updatedItem) + const newItemTotal = this.calculateItemPrice( + updatedItem, + updatedItem.quantity + ) + this.total = +(this.total - oldItemTotal + newItemTotal).toFixed(2) this.cartTaxTotal() }, calculateItemPrice(item, qty) { diff --git a/templates/tpos/_cart.html b/templates/tpos/_cart.html index 382ef3d..35fa99b 100644 --- a/templates/tpos/_cart.html +++ b/templates/tpos/_cart.html @@ -66,7 +66,11 @@