forked from crudo/macao-pos
Compare commits
16 Commits
breakthebo
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
68b59ce478 | ||
1b3fa43a23 | |||
257eba61b0 | |||
ce0092303f | |||
65e42c0c6e | |||
8dab5b7ab2 | |||
71ba505c8b | |||
2cf749fd6f | |||
a6e878c6fd | |||
819a38e2d3 | |||
729402ef6d | |||
b93478ac85 | |||
c771aaadbc | |||
800be08471 | |||
22476bfb7b | |||
96ccea0899 |
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -96,4 +96,4 @@ ENV/
|
|||
# macao-pos files
|
||||
conf/
|
||||
pos.db
|
||||
pos.log
|
||||
pos.log*
|
||||
|
|
12
README.md
12
README.md
|
@ -58,12 +58,12 @@ python3 cli.py user add username password
|
|||
Add some products with:
|
||||
|
||||
```
|
||||
python3 cli.py product add "Birra media" 300
|
||||
python3 cli.py product add "Birra grande" 400
|
||||
python3 cli.py product add "Cocktail" 500
|
||||
python3 cli.py product add "Vino" 400
|
||||
python3 cli.py product add "Amaro" 200
|
||||
python3 cli.py product add "Acqua" 100
|
||||
python3 cli.py product add "Birra media" 3
|
||||
python3 cli.py product add "Birra grande" 4
|
||||
python3 cli.py product add "Cocktail" 5
|
||||
python3 cli.py product add "Vino" 4
|
||||
python3 cli.py product add "Amaro" 2
|
||||
python3 cli.py product add "Acqua" 0.5
|
||||
```
|
||||
|
||||
And finally add and event you can play with:
|
||||
|
|
3
cli.py
3
cli.py
|
@ -289,10 +289,11 @@ def tabulate_products(products):
|
|||
|
||||
@product.command('add')
|
||||
@click.argument('name')
|
||||
@click.argument('price')
|
||||
@click.argument('price', type=float)
|
||||
@click.option('-s', '--sort', type=click.INT)
|
||||
@click.option('-c', '--category', type=click.INT)
|
||||
def product_add(name, price, sort, category):
|
||||
price = int(price * 100)
|
||||
product = Product(name=name, price=price)
|
||||
|
||||
if sort:
|
||||
|
|
56
static/js/sell.js
Normal file
56
static/js/sell.js
Normal file
|
@ -0,0 +1,56 @@
|
|||
function updateTotal(amount) {
|
||||
total_el = document.getElementById('total')
|
||||
total = parseFloat(total_el.innerText)
|
||||
total += amount
|
||||
total_el.innerText = total.toFixed(2)
|
||||
}
|
||||
|
||||
function renderBasketItem(uid, name) {
|
||||
return '<button id="basketitem_' + uid + '"' +
|
||||
'onclick="delProduct(' + uid + ')">' +
|
||||
'1 x ' + name +
|
||||
'</button>'
|
||||
}
|
||||
|
||||
function addProduct(uid) {
|
||||
// This is the hidden input element inside the form. We'll use this DOM
|
||||
// element to keep informations about the product, such as the name,
|
||||
// the price and the value inside the 'data-' tag.
|
||||
form_el = document.getElementById('prod_' + uid)
|
||||
basket = document.getElementById('basket')
|
||||
basket_el = document.getElementById('basketitem_' + uid)
|
||||
|
||||
form_el.value = parseInt(form_el.value) + 1
|
||||
|
||||
// If there is not a button for the given product inside the basket
|
||||
// div we'll create it.
|
||||
if (basket_el === null) {
|
||||
basket.innerHTML += renderBasketItem(uid, form_el.dataset.name)
|
||||
} else {
|
||||
// Otherwise we'll just update it.
|
||||
console.log(form_el.value)
|
||||
new_text = form_el.value + ' x ' + form_el.dataset.name
|
||||
basket_el.innerText = new_text
|
||||
}
|
||||
|
||||
updateTotal(parseFloat(form_el.dataset.price))
|
||||
}
|
||||
|
||||
function delProduct(uid) {
|
||||
form_el = document.getElementById('prod_' + uid)
|
||||
basket = document.getElementById('basket')
|
||||
basket_el = document.getElementById('basketitem_' + uid)
|
||||
|
||||
form_el.value = parseInt(form_el.value) - 1
|
||||
|
||||
if (form_el.value == 0) {
|
||||
basket.removeChild(basket_el)
|
||||
} else {
|
||||
new_text = form_el.value + ' x ' + form_el.dataset.name
|
||||
basket_el.innerText = new_text
|
||||
}
|
||||
|
||||
updateTotal(parseFloat(-form_el.dataset.price))
|
||||
}
|
||||
|
||||
|
|
@ -27,66 +27,10 @@
|
|||
</form>
|
||||
|
||||
</div>
|
||||
<script type="text/javascript" src="{{ url_for('static', filename='js/sell.js') }}">
|
||||
<script type="text/javascript">
|
||||
function reset() {
|
||||
{%- for product in products %}
|
||||
document.getElementById('prod_{{ product.uid }}').value = 0
|
||||
document.getElementById('prod_{{ product.uid }}').value = 0
|
||||
{%- endfor %}
|
||||
}
|
||||
|
||||
function updateTotal(amount) {
|
||||
total_el = document.getElementById('total')
|
||||
total = parseFloat(total_el.innerText)
|
||||
total += amount
|
||||
total_el.innerText = total.toFixed(2)
|
||||
}
|
||||
|
||||
function addProduct(uid) {
|
||||
// This is the hidden input element inside the form. We'll use this DOM
|
||||
// element to keep informations about the product, such as the name,
|
||||
// the price and the value inside the 'data-' tag.
|
||||
form_el = document.getElementById('prod_' + uid)
|
||||
basket = document.getElementById('basket')
|
||||
basket_el = document.getElementById('basketitem_' + uid)
|
||||
|
||||
form_el.value = parseInt(form_el.value) + 1
|
||||
|
||||
// If there is not a button for the given product inside the basket
|
||||
// div we'll create it.
|
||||
if (basket_el === null) {
|
||||
new_basket_el =
|
||||
'<button id="basketitem_' + uid + '"' +
|
||||
'onclick="delProduct(' + uid + ')">' +
|
||||
'1 x ' + form_el.dataset.name +
|
||||
'</button>'
|
||||
basket.innerHTML += new_basket_el
|
||||
} else {
|
||||
// Otherwise we'll just update it.
|
||||
console.log(form_el.value)
|
||||
new_text = form_el.value + ' x ' + form_el.dataset.name
|
||||
basket_el.innerText = new_text
|
||||
}
|
||||
|
||||
updateTotal(parseFloat(form_el.dataset.price))
|
||||
}
|
||||
|
||||
function delProduct(uid) {
|
||||
form_el = document.getElementById('prod_' + uid)
|
||||
basket = document.getElementById('basket')
|
||||
basket_el = document.getElementById('basketitem_' + uid)
|
||||
|
||||
form_el.value = parseInt(form_el.value) - 1
|
||||
|
||||
if (form_el.value == 0) {
|
||||
basket.removeChild(basket_el)
|
||||
} else {
|
||||
new_text = form_el.value + ' x ' + form_el.dataset.name
|
||||
basket_el.innerText = new_text
|
||||
}
|
||||
|
||||
updateTotal(parseFloat(-form_el.dataset.price))
|
||||
}
|
||||
|
||||
reset()
|
||||
</script>
|
||||
{% endblock %}
|
||||
|
|
Loading…
Reference in New Issue
Block a user