From d7ddd5de53a9601be2fdafc7a8751c6119d2a90a Mon Sep 17 00:00:00 2001 From: Yannick Tivisse Date: Wed, 14 Jul 2021 15:13:53 +0200 Subject: [PATCH] [IMP] lunch: Store the lunch location on lunch orders --- addons/lunch/data/lunch_demo.xml | 5 +++++ addons/lunch/models/lunch_order.py | 10 ++++++---- addons/lunch/models/lunch_supplier.py | 2 ++ addons/lunch/security/lunch_security.xml | 6 ++++++ addons/lunch/static/src/scss/lunch_view.scss | 9 --------- addons/lunch/tests/test_supplier.py | 18 ++++++++++++------ addons/lunch/views/lunch_orders_views.xml | 8 +++++--- addons/lunch/views/lunch_product_views.xml | 3 ++- .../webclient/commands/command_palette.scss | 4 ---- 9 files changed, 38 insertions(+), 27 deletions(-) diff --git a/addons/lunch/data/lunch_demo.xml b/addons/lunch/data/lunch_demo.xml index e9c1f8d8f01..799c212446f 100644 --- a/addons/lunch/data/lunch_demo.xml +++ b/addons/lunch/data/lunch_demo.xml @@ -423,6 +423,7 @@ new 1 + @@ -433,6 +434,7 @@ confirmed 1 + @@ -443,6 +445,7 @@ cancelled 1 + @@ -453,6 +456,7 @@ confirmed 1 + @@ -462,6 +466,7 @@ confirmed + diff --git a/addons/lunch/models/lunch_order.py b/addons/lunch/models/lunch_order.py index 1c4d8364831..794b00803c0 100644 --- a/addons/lunch/models/lunch_order.py +++ b/addons/lunch/models/lunch_order.py @@ -26,6 +26,7 @@ class LunchOrder(models.Model): user_id = fields.Many2one('res.users', 'User', readonly=True, states={'new': [('readonly', False)]}, default=lambda self: self.env.uid) + lunch_location_id = fields.Many2one('lunch.location', default=lambda self: self.env.user.last_lunch_location_id) note = fields.Text('Notes') price = fields.Monetary('Total Price', compute='_compute_total_price', readonly=True, store=True) active = fields.Boolean('Active', default=True) @@ -149,9 +150,6 @@ class LunchOrder(models.Model): }) if matching_lines: lines_to_deactivate |= line - # YTI TODO Try to batch it, be careful there might be multiple matching - # lines for the same order hence quantity should not always be - # line.quantity, but rather a sum matching_lines.update_quantity(line.quantity) lines_to_deactivate.write({'active': False}) return super(LunchOrder, self - lines_to_deactivate).write(values) @@ -205,7 +203,11 @@ class LunchOrder(models.Model): def action_order(self): if self.filtered(lambda line: not line.product_id.active): raise ValidationError(_('Product is no longer available.')) - self.write({'state': 'ordered'}) + self.write({ + 'state': 'ordered', + }) + for order in self: + order.lunch_location_id = order.user_id.last_lunch_location_id self._check_wallet() def action_reorder(self): diff --git a/addons/lunch/models/lunch_supplier.py b/addons/lunch/models/lunch_supplier.py index 765179b51e5..d3b205d8da6 100644 --- a/addons/lunch/models/lunch_supplier.py +++ b/addons/lunch/models/lunch_supplier.py @@ -187,6 +187,8 @@ class LunchSupplier(models.Model): topping_values = topping[2] if topping_values: topping_values.update({'topping_category': 3}) + if values.get('company_id'): + self.env['lunch.order'].search([('supplier_id', 'in', self.ids)]).write({'company_id': values['company_id']}) super().write(values) if not CRON_DEPENDS.isdisjoint(values): self._sync_cron() diff --git a/addons/lunch/security/lunch_security.xml b/addons/lunch/security/lunch_security.xml index fa374a00c67..cedbab1eccf 100644 --- a/addons/lunch/security/lunch_security.xml +++ b/addons/lunch/security/lunch_security.xml @@ -71,6 +71,12 @@ ['|', ('company_id', '=', False), ('company_id', 'in', company_ids)] + + Lunch order: Multi Company + + ['|', ('company_id', '=', False), ('company_id', 'in', company_ids)] + + Lunch product: Multi Company diff --git a/addons/lunch/static/src/scss/lunch_view.scss b/addons/lunch/static/src/scss/lunch_view.scss index a19834d809f..6b7056f96f7 100644 --- a/addons/lunch/static/src/scss/lunch_view.scss +++ b/addons/lunch/static/src/scss/lunch_view.scss @@ -9,9 +9,6 @@ flex: 0 0 auto; border-bottom: 1px solid #CED4DA; background-color: white; - position: fixed; - z-index: 50; - width: 90%; } .o_lunch_purple { @@ -53,12 +50,6 @@ } } -.o_kanban_view { - &.o_lunch_kanban_view { - padding-top: 11rem; - } -} - .o_lunch_image { img { max-width: 128px; diff --git a/addons/lunch/tests/test_supplier.py b/addons/lunch/tests/test_supplier.py index 9040db7befd..1d2f901c2ba 100644 --- a/addons/lunch/tests/test_supplier.py +++ b/addons/lunch/tests/test_supplier.py @@ -86,7 +86,8 @@ env['lunch.supplier'].browse([{self.supplier_kothai.id}])._send_auto_email()""") with patch.object(fields.Date, 'context_today', return_value=self.monday_1pm.date()) as _: line = self.env['lunch.order'].create({ 'product_id': self.product_pizza.id, - 'date': self.monday_1pm.date() + 'date': self.monday_1pm.date(), + 'supplier_id': self.supplier_pizza_inn.id, }) line.action_order() @@ -99,11 +100,13 @@ env['lunch.supplier'].browse([{self.supplier_kothai.id}])._send_auto_email()""") line = self.env['lunch.order'].create({ 'product_id': self.product_pizza.id, 'topping_ids_1': [(6, 0, [self.topping_olives.id])], - 'date': self.monday_1pm.date() + 'date': self.monday_1pm.date(), + 'supplier_id': self.supplier_pizza_inn.id, }) line2 = self.env['lunch.order'].create({ 'product_id': self.product_sandwich_tuna.id, - 'date': self.monday_1pm.date() + 'date': self.monday_1pm.date(), + 'supplier_id': self.supplier_coin_gourmand.id, }) (line | line2).action_order() @@ -118,19 +121,22 @@ env['lunch.supplier'].browse([{self.supplier_kothai.id}])._send_auto_email()""") line_1 = self.env['lunch.order'].create({ 'product_id': self.product_pizza.id, 'quantity': 2, - 'date': self.monday_1pm.date() + 'date': self.monday_1pm.date(), + 'supplier_id': self.product_pizza.id, }) line_2 = self.env['lunch.order'].create({ 'product_id': self.product_pizza.id, 'topping_ids_1': [(6, 0, [self.topping_olives.id])], - 'date': self.monday_1pm.date() + 'date': self.monday_1pm.date(), + 'supplier_id': self.product_pizza.id, }) line_3 = self.env['lunch.order'].create({ 'product_id': self.product_sandwich_tuna.id, 'quantity': 2, - 'date': self.monday_1pm.date() + 'date': self.monday_1pm.date(), + 'supplier_id': self.supplier_coin_gourmand.id, }) (line_1 | line_2 | line_3).action_order() diff --git a/addons/lunch/views/lunch_orders_views.xml b/addons/lunch/views/lunch_orders_views.xml index 0e876644370..15017e4b8bf 100644 --- a/addons/lunch/views/lunch_orders_views.xml +++ b/addons/lunch/views/lunch_orders_views.xml @@ -40,6 +40,7 @@ + @@ -193,6 +194,7 @@ +
@@ -208,7 +210,7 @@
- +
@@ -216,7 +218,7 @@
- +
@@ -224,7 +226,7 @@
- +
diff --git a/addons/lunch/views/lunch_product_views.xml b/addons/lunch/views/lunch_product_views.xml index efca75e6628..c92dede9b57 100644 --- a/addons/lunch/views/lunch_product_views.xml +++ b/addons/lunch/views/lunch_product_views.xml @@ -10,7 +10,6 @@ - @@ -20,6 +19,8 @@ + + diff --git a/addons/web/static/src/webclient/commands/command_palette.scss b/addons/web/static/src/webclient/commands/command_palette.scss index 43d35e8166f..19d844f3446 100644 --- a/addons/web/static/src/webclient/commands/command_palette.scss +++ b/addons/web/static/src/webclient/commands/command_palette.scss @@ -60,10 +60,6 @@ line-height: 1.8em; height: 2.8em; - &.focused { - background: #00a09d26; - } - kbd { background-color: #f4f7f8; border-radius: 3px;