diff --git a/ihatemoney/forms.py b/ihatemoney/forms.py index a55166e8..d2316fda 100644 --- a/ihatemoney/forms.py +++ b/ihatemoney/forms.py @@ -11,7 +11,7 @@ from markupsafe import Markup from werkzeug.security import check_password_hash, generate_password_hash from wtforms.fields.core import Label, SelectField, SelectMultipleField from wtforms.fields.html5 import DateField, DecimalField, URLField -from wtforms.fields.simple import BooleanField, PasswordField, StringField, SubmitField +from wtforms.fields.simple import BooleanField, PasswordField, StringField, SubmitField, HiddenField from wtforms.validators import ( URL, DataRequired, @@ -310,6 +310,7 @@ class BillForm(FlaskForm): amount = CalculatorStringField(_("How much?"), validators=[DataRequired()]) currency_helper = CurrencyConverter() original_currency = SelectField(_("Currency"), validators=[DataRequired()]) + tag = HiddenField(_("Tag"), default="") external_link = URLField( _("External link"), validators=[Optional(), URL()], @@ -325,6 +326,9 @@ class BillForm(FlaskForm): bill.payer_id = self.payer.data bill.amount = self.amount.data bill.what = self.what.data + tag = list(set(part[1:] for part in bill.what.split() if part.startswith('#'))) + if tag: + bill.tag = tag[0] bill.external_link = self.external_link.data bill.date = self.date.data bill.owers = [Person.query.get(ower, project) for ower in self.payed_for.data] @@ -338,6 +342,7 @@ class BillForm(FlaskForm): bill.payer_id = self.payer bill.amount = self.amount bill.what = self.what + bill.tag = self.tag bill.external_link = "" bill.date = self.date bill.owers = [Person.query.get(ower, project) for ower in self.payed_for] @@ -352,6 +357,7 @@ class BillForm(FlaskForm): self.payer.data = bill.payer_id self.amount.data = bill.amount self.what.data = bill.what + self.tag.data = bill.tag self.external_link.data = bill.external_link self.original_currency.data = bill.original_currency self.date.data = bill.date diff --git a/ihatemoney/migrations/versions/49fc258cebf5_added_tag_column_to_bill_model.py b/ihatemoney/migrations/versions/49fc258cebf5_added_tag_column_to_bill_model.py new file mode 100644 index 00000000..80bacf55 --- /dev/null +++ b/ihatemoney/migrations/versions/49fc258cebf5_added_tag_column_to_bill_model.py @@ -0,0 +1,31 @@ +"""added tag column to bill model + +Revision ID: 49fc258cebf5 +Revises: 927ed575acbd +Create Date: 2020-04-23 13:13:08.094805 + +""" + +# revision identifiers, used by Alembic. +revision = "49fc258cebf5" +down_revision = "927ed575acbd" + +from alembic import op +import sqlalchemy as sa + + +def upgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.add_column("bill", sa.Column("tag", sa.UnicodeText(), nullable=True)) + op.add_column( + "bill_version", + sa.Column("tag", sa.UnicodeText(), autoincrement=False, nullable=True), + ) + # ### end Alembic commands ### + + +def downgrade(): + # ### commands auto generated by Alembic - please adjust! ### + op.drop_column("bill_version", "tag") + op.drop_column("bill", "tag") + # ### end Alembic commands ### diff --git a/ihatemoney/models.py b/ihatemoney/models.py index 473e7c0b..e6729292 100644 --- a/ihatemoney/models.py +++ b/ihatemoney/models.py @@ -554,6 +554,7 @@ class Bill(db.Model): date = db.Column(db.Date, default=datetime.now) creation_date = db.Column(db.Date, default=datetime.now) what = db.Column(db.UnicodeText) + tag = db.Column(db.UnicodeText) external_link = db.Column(db.UnicodeText) original_currency = db.Column(db.String(3)) @@ -571,6 +572,7 @@ class Bill(db.Model): "date": self.date, "creation_date": self.creation_date, "what": self.what, + "tag": self.tag, "external_link": self.external_link, "original_currency": self.original_currency, "converted_amount": self.converted_amount, diff --git a/ihatemoney/templates/list_bills.html b/ihatemoney/templates/list_bills.html index 61420d51..1663ca99 100644 --- a/ihatemoney/templates/list_bills.html +++ b/ihatemoney/templates/list_bills.html @@ -21,6 +21,16 @@ }); }); + // remove duplicate tags + var usedTags = {}; + $("select[name='tag-search-select'] > option").each(function() { + if (usedTags[this.text]) { + $(this).remove(); + } else { + usedTags[this.text] = this.value; + } + }); + var highlight_owers = function(){ var ower_ids = $(this).attr("owers").split(','); var payer_id = $(this).attr("payer"); @@ -110,7 +120,7 @@
{% for bill in bills.items %} -