Skip to content
Permalink
Browse files

[IMP] lunch: Improve the product dashboard

The default image for the lunch product should be the one from the
category (added an image on the categories).

In case there is no image either on the product either on the category,
in the kanban view there should be a specific image (fork and knife
image)

Added some data in order to always have something displayed in the
kanban view

Fixed the layout of the dashboard

Bug fix, in `_check_wallet` there was a flush missing

Bug fix, `product_id` should be a many2one, not an integer field and the
orm should be used in order to avoid problems when favoriting products

This is a back2basics task

Task 2048246
  • Loading branch information...
RomainLibert committed Aug 26, 2019
1 parent 2ad8d8c commit cb85bab8080ba1be1cad0bf34be869e869a5d594
@@ -1,6 +1,88 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record id="lunch_location_main" model="lunch.location">
<field name="name">HQ Office</field>
<field name="address">87323 Francis Corner Oscarhaven, OK 12782</field>
</record>

<record model="lunch.product.category" id="categ_sandwich">
<field name="name">Sandwich</field>
</record>

<record id="categ_pizza" model="lunch.product.category">
<field name="name">Pizza</field>
<field name="image_1920" type="base64" file="lunch/static/img/pizza.png"/>
</record>

<record id="categ_burger" model="lunch.product.category">
<field name="name">Burger</field>
<field name="image_1920" type="base64" file="lunch/static/img/burger.png"/>
</record>

<record id="categ_drinks" model="lunch.product.category">
<field name="name">Drinks</field>
<field name="image_1920" type="base64" file="lunch/static/img/drink.png"/>
</record>

<record id="partner_hungry_dog" model="res.partner">
<field name="name">Hungry Dog</field>
<field name="city">Russeltown</field>
<field name="country_id" ref="base.us"/>
<field name="street">975 Bullock Orchard</field>
<field name="zip">02155</field>
<field name="email">cynthiasanchez@gmail.com</field>
</record>

<record id="supplier_hungry_dog" model="lunch.supplier">
<field name="partner_id" ref="partner_hungry_dog"/>
<field name="available_location_ids" eval="[
(6, 0, [ref('lunch_location_main')]),
]"/>
</record>

<record id="product_bacon_0" model="lunch.product">
<field name="name">Bacon</field>
<field name="category_id" ref="categ_burger"/>
<field name="price">7.2</field>
<field name="supplier_id" ref="supplier_hungry_dog"/>
<field name="description">Beef, Bacon, Salad, Cheddar, Fried Onion, BBQ Sauce</field>
<field name="image_1920" type="base64" file="lunch/static/img/bacon_burger.png"/>
</record>

<record id="product_cheese_burger_0" model="lunch.product">
<field name="name">Cheese Burger</field>
<field name="category_id" ref="categ_burger"/>
<field name="price">6.8</field>
<field name="supplier_id" ref="supplier_hungry_dog"/>
<field name="description">Beef, Cheddar, Salad, Fried Onions, BBQ Sauce</field>
<field name="image_1920" type="base64" file="lunch/static/img/cheeseburger.png"/>
</record>

<record id="product_club_0" model="lunch.product">
<field name="name">Club</field>
<field name="category_id" ref="categ_sandwich"/>
<field name="price">3.4</field>
<field name="supplier_id" ref="supplier_hungry_dog"/>
<field name="description">Ham, Cheese, Vegetables</field>
<field name="image_1920" type="base64" file="lunch/static/img/club.png"/>
</record>

<record id="product_coke_0" model="lunch.product">
<field name="name">Coca Cola</field>
<field name="category_id" ref="categ_drinks"/>
<field name="price">2.9</field>
<field name="supplier_id" ref="supplier_hungry_dog"/>
</record>

<record id="product_pizza_0" model="lunch.product">
<field name="name">Pizza Margherita</field>
<field name="category_id" ref="categ_pizza"/>
<field name="price">6.90</field>
<field name="supplier_id" ref="supplier_hungry_dog"/>
<field name="description">Tomatoes, Mozzarella</field>
</record>

<record id="lunch_order_action_confirm" model="ir.actions.server">
<field name="name">Lunch: Receive meals</field>
<field name="model_id" ref="model_lunch_order"/>
@@ -23,24 +23,18 @@
<field name="groups_id" eval="[(4, ref('lunch.group_lunch_user'))]"/>
</record>

<record model="lunch.product.category" id="categ_sandwich">
<field name="name">Sandwich</field>
</record>
<record model="lunch.product.category" id="categ_pizza">
<field name="name">Pizza</field>
</record>
<record model="lunch.product.category" id="categ_pasta">
<field name="name">Pasta</field>
</record>
<record model="lunch.product.category" id="categ_burger">
<field name="name">Burger</field>
</record>

<record model="lunch.product.category" id="categ_sushi">
<field name="name">Sushi</field>
</record>

<record model="lunch.product.category" id="categ_temaki">
<field name="name">Temaki</field>
</record>

<record model="lunch.product.category" id="categ_chirashi">
<field name="name">Chirashi</field>
</record>
@@ -66,6 +66,7 @@ def update_quantity(self, increment):
self._check_wallet()

def _check_wallet(self):
self.flush()
for line in self:
if self.env['lunch.cashmove'].get_wallet_balance(line.user_id) < 0:
raise ValidationError(_('Your wallet does not contain enough money to order that.'
@@ -9,6 +9,7 @@
class LunchProductCategory(models.Model):
""" Category of the product such as pizza, sandwich, pasta, chinese, burger... """
_name = 'lunch.product.category'
_inherit = 'image.mixin'
_description = 'Lunch Product Category'

name = fields.Char('Product Category', required=True)
@@ -8,3 +8,4 @@ class ResUsers(models.Model):
_inherit = 'res.users'

last_lunch_location_id = fields.Many2one('lunch.location')
favorite_lunch_product_ids = fields.Many2many('lunch.product', 'lunch_product_favorite_user_rel', 'user_id', 'product_id')
@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from odoo import api, fields, models, tools
from odoo import fields, models, tools
from odoo.osv import expression


@@ -12,7 +12,7 @@ class LunchProductReport(models.Model):
_order = 'is_favorite desc, is_new desc, last_order_date asc, product_id asc'

id = fields.Integer('ID')
product_id = fields.Integer('Product ID')
product_id = fields.Many2one('lunch.product', 'Product')
name = fields.Char('Product Name')
category_id = fields.Many2one('lunch.product.category', 'Product Category')
description = fields.Text('Description')
@@ -25,10 +25,22 @@ class LunchProductReport(models.Model):
is_new = fields.Boolean('New')
active = fields.Boolean('Active')
last_order_date = fields.Date('Last Order Date')
image_128 = fields.Image(compute="_compute_image_128")

# This field is used only for searching
is_available_at = fields.Many2one('lunch.location', 'Product Availability', compute='_compute_is_available_at', search='_search_is_available_at')

def _compute_image_128(self):
for product_r in self:
product = product_r.product_id
category = product_r.category_id
if product.image_128:
product_r.image_128 = product.image_128
elif category.image_128:
product_r.image_128 = category.image_128
else:
product_r.image_128 = False

def _compute_is_available_at(self):
"""
Is available_at is always false when browsing it
@@ -52,15 +64,14 @@ def _search_is_available_at(self, operator, value):
return expression.OR([[('supplier_id.available_location_ids', 'in', value)], [('supplier_id.available_location_ids', '=', False)]])

def write(self, values):
user_id = self.env.user.id
if 'is_favorite' in values:
for report in self:
if values['is_favorite']:
self.env.cr.execute('''INSERT INTO lunch_product_favorite_user_rel(product_id, user_id) VALUES (%s, %s)''',
(report.product_id, user_id))
else:
self.env.cr.execute('''DELETE FROM lunch_product_favorite_user_rel WHERE product_id=%s AND user_id=%s''',
(report.product_id, user_id))
if values['is_favorite']:
commands = [(4, product_id) for product_id in self.mapped('product_id').ids]
else:
commands = [(3, product_id) for product_id in self.mapped('product_id').ids]
self.env.user.write({
'favorite_lunch_product_ids': commands,
})

def init(self):
tools.drop_view_if_exists(self._cr, self._table)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -26,7 +26,7 @@ odoo.define('lunch.LunchKanbanRecord', function (require) {
ev.preventDefault();
// ignore clicks on oe_kanban_action elements
if (!$(ev.target).hasClass('oe_kanban_action')) {
this.trigger_up('open_wizard', {productId: this.recordData.product_id});
this.trigger_up('open_wizard', {productId: this.recordData.product_id ? this.recordData.product_id.res_id: this.recordData.id});
}
},
});

0 comments on commit cb85bab

Please sign in to comment.
You can’t perform that action at this time.