[IMP] lunch: Store the lunch location on lunch orders

This commit is contained in:
Yannick Tivisse
2021-07-16 12:02:56 +02:00
parent fcc22bbabf
commit d7ddd5de53
9 changed files with 38 additions and 27 deletions
+5
View File
@@ -423,6 +423,7 @@
<field name="state">new</field>
<field name="supplier_id" ref="supplier_pizza_inn"/>
<field name="quantity">1</field>
<field name="lunch_location_id" ref="location_office_3"/>
</record>
<record model="lunch.order" id="order_line_2">
@@ -433,6 +434,7 @@
<field name="state">confirmed</field>
<field name="supplier_id" ref="supplier_pizza_inn"/>
<field name="quantity">1</field>
<field name="lunch_location_id" ref="location_office_3"/>
</record>
<record model="lunch.order" id="order_line_3">
@@ -443,6 +445,7 @@
<field name="state">cancelled</field>
<field name="supplier_id" ref="supplier_coin_gourmand"/>
<field name="quantity">1</field>
<field name="lunch_location_id" ref="location_office_3"/>
</record>
<record model="lunch.order" id="order_line_4">
@@ -453,6 +456,7 @@
<field name="state">confirmed</field>
<field name="supplier_id" ref="supplier_coin_gourmand"/>
<field name="quantity">1</field>
<field name="lunch_location_id" ref="location_office_3"/>
</record>
<record model="lunch.order" id="order_line_5">
@@ -462,6 +466,7 @@
<field name="date" eval="(DateTime.now() + timedelta(days=3)).strftime('%Y-%m-%d')"/>
<field name="state">confirmed</field>
<field name="supplier_id" ref="supplier_pizza_inn"/>
<field name="lunch_location_id" ref="location_office_2"/>
</record>
</data>
</odoo>
+6 -4
View File
@@ -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):
+2
View File
@@ -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()
+6
View File
@@ -71,6 +71,12 @@
<field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
</record>
<record id="ir_rule_lunch_order_multi_company" model="ir.rule">
<field name="name">Lunch order: Multi Company</field>
<field name="model_id" ref="model_lunch_order"/>
<field name="domain_force">['|', ('company_id', '=', False), ('company_id', 'in', company_ids)]</field>
</record>
<record id="ir_rule_lunch_product_multi_company" model="ir.rule">
<field name="name">Lunch product: Multi Company</field>
<field name="model_id" ref="model_lunch_product"/>
@@ -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;
+12 -6
View File
@@ -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()
+5 -3
View File
@@ -40,6 +40,7 @@
<field name="display_toppings" class="o_text_overflow"/>
<field name='note' class="o_text_overflow"/>
<field name='user_id'/>
<field name="lunch_location_id"/>
<field name="currency_id" invisible="1"/>
<field name='price' sum="Total" string="Price" widget="monetary"/>
<field name='state'/>
@@ -193,6 +194,7 @@
<field name="available_toppings_1" invisible="1"/>
<field name="available_toppings_2" invisible="1"/>
<field name="available_toppings_3" invisible="1"/>
<field name="supplier_id" invisible="1"/>
<div class="d-flex">
<div class="flex-grow-0 pr-5">
<field name="image_1920" widget="image" class="o_lunch_image" options="{'image_preview': 'image_128'}"/>
@@ -208,7 +210,7 @@
<field name="topping_label_1" nolabel="1" attrs="{'invisible': [('available_toppings_1', '=', False)]}" class="font-weight-bold"/>
</div>
<div class="col-10">
<field name="topping_ids_1" attrs="{'invisible': [('available_toppings_1', '=', False)]}" widget="many2many_checkboxes" nolabel="1"/>
<field name="topping_ids_1" attrs="{'invisible': [('available_toppings_1', '=', False)]}" widget="many2many_checkboxes" nolabel="1" domain="[('topping_category', '=', 1), ('supplier_id', '=', supplier_id)]"/>
</div>
</div>
<div class="row">
@@ -216,7 +218,7 @@
<field name="topping_label_2" nolabel="1" attrs="{'invisible': [('available_toppings_2', '=', False)]}" class="font-weight-bold"/>
</div>
<div class="col-10">
<field name="topping_ids_2" attrs="{'invisible': [('available_toppings_2', '=', False)]}" widget="many2many_checkboxes" nolabel="1"/>
<field name="topping_ids_2" attrs="{'invisible': [('available_toppings_2', '=', False)]}" widget="many2many_checkboxes" nolabel="1" domain="[('topping_category', '=', 2), ('supplier_id', '=', supplier_id)]"/>
</div>
</div>
<div class="row">
@@ -224,7 +226,7 @@
<field name="topping_label_3" nolabel="1" attrs="{'invisible': [('available_toppings_3', '=', False)]}" class="font-weight-bold"/>
</div>
<div class="col-10">
<field name="topping_ids_3" attrs="{'invisible': [('available_toppings_3', '=', False)]}" widget="many2many_checkboxes" nolabel="1"/>
<field name="topping_ids_3" attrs="{'invisible': [('available_toppings_3', '=', False)]}" widget="many2many_checkboxes" nolabel="1" domain="[('topping_category', '=', 3), ('supplier_id', '=', supplier_id)]"/>
</div>
</div>
<div class="row">
+2 -1
View File
@@ -10,7 +10,6 @@
<field name="supplier_id"/>
<field name="description"/>
<separator/>
<filter name="inactive" string="Archived" domain="[('active', '=', False)]"/>
<filter name="available_today" string="Available Today" domain="[('supplier_id.available_today', '=', True)]"/>
<separator/>
<filter name="available_on_mon" string="Monday" domain="[('supplier_id.mon', '=', True)]"/>
@@ -20,6 +19,8 @@
<filter name="available_on_fri" string="Friday" domain="[('supplier_id.fri', '=', True)]"/>
<filter name="available_on_sat" string="Saturday" domain="[('supplier_id.sat', '=', True)]"/>
<filter name="available_on_sun" string="Sunday" domain="[('supplier_id.sun', '=', True)]"/>
<separator/>
<filter name="inactive" string="Archived" domain="[('active', '=', False)]"/>
<group expand="0" string="Group By">
<filter name="group_by_supplier" string="Vendor" context="{'group_by': 'supplier_id'}"/>
<filter name="group_by_category" string="Category" context="{'group_by': 'category_id'}"/>
@@ -60,10 +60,6 @@
line-height: 1.8em;
height: 2.8em;
&.focused {
background: #00a09d26;
}
kbd {
background-color: #f4f7f8;
border-radius: 3px;