[IMP] lunch: Allow to reorder a previous order from "My Orders"
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import api, fields, models, _
|
||||
from odoo.exceptions import ValidationError
|
||||
from odoo.exceptions import ValidationError, UserError
|
||||
|
||||
|
||||
class LunchOrder(models.Model):
|
||||
@@ -53,6 +53,7 @@ class LunchOrder(models.Model):
|
||||
available_toppings_1 = fields.Boolean(help='Are extras available for this product', compute='_compute_available_toppings')
|
||||
available_toppings_2 = fields.Boolean(help='Are extras available for this product', compute='_compute_available_toppings')
|
||||
available_toppings_3 = fields.Boolean(help='Are extras available for this product', compute='_compute_available_toppings')
|
||||
display_reorder_button = fields.Boolean(compute='_compute_display_reorder_button')
|
||||
|
||||
@api.depends('product_id')
|
||||
def _compute_product_images(self):
|
||||
@@ -67,6 +68,13 @@ class LunchOrder(models.Model):
|
||||
order.available_toppings_2 = bool(order.env['lunch.topping'].search_count([('supplier_id', '=', order.supplier_id.id), ('topping_category', '=', 2)]))
|
||||
order.available_toppings_3 = bool(order.env['lunch.topping'].search_count([('supplier_id', '=', order.supplier_id.id), ('topping_category', '=', 3)]))
|
||||
|
||||
@api.depends_context('show_reorder_button')
|
||||
@api.depends('state')
|
||||
def _compute_display_reorder_button(self):
|
||||
show_button = self.env.context.get('show_reorder_button')
|
||||
for order in self:
|
||||
order.display_reorder_button = show_button and order.state == 'confirmed'
|
||||
|
||||
def init(self):
|
||||
self._cr.execute("""CREATE INDEX IF NOT EXISTS lunch_order_user_product_date ON %s (user_id, product_id, date)"""
|
||||
% self._table)
|
||||
@@ -200,6 +208,17 @@ class LunchOrder(models.Model):
|
||||
self.write({'state': 'ordered'})
|
||||
self._check_wallet()
|
||||
|
||||
def action_reorder(self):
|
||||
self.ensure_one()
|
||||
if not self.supplier_id.available_today:
|
||||
raise UserError(_('The vendor related to this order is not available today.'))
|
||||
self.copy({
|
||||
'date': fields.Date.context_today(self),
|
||||
'state': 'ordered',
|
||||
})
|
||||
action = self.env['ir.actions.act_window']._for_xml_id('lunch.lunch_order_action')
|
||||
return action
|
||||
|
||||
def action_confirm(self):
|
||||
self.write({'state': 'confirmed'})
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
<button name="action_confirm" type="object" string="Receive"/>
|
||||
</header>
|
||||
<field name='date'/>
|
||||
<field name='supplier_id' invisible='1'/>
|
||||
<field name='supplier_id'/>
|
||||
<field name='product_id'/>
|
||||
<field name="display_toppings" class="o_text_overflow"/>
|
||||
<field name='note' class="o_text_overflow"/>
|
||||
@@ -44,6 +44,8 @@
|
||||
<field name='price' sum="Total" string="Price" widget="monetary"/>
|
||||
<field name='state'/>
|
||||
<field name="company_id" groups="base.group_multi_company"/>
|
||||
<field name="display_reorder_button" invisible="1"/>
|
||||
<button name="action_reorder" string="Re-order" type="object" icon="fa-history" attrs="{'invisible': [('display_reorder_button', '=', False)]}" groups="lunch.group_lunch_user"/>
|
||||
<button name="action_confirm" string="Confirm" type="object" icon="fa-check" attrs="{'invisible': [('state', '!=', 'ordered')]}" groups="lunch.group_lunch_manager"/>
|
||||
<button name="action_cancel" string="Cancel" type="object" icon="fa-times" attrs="{'invisible': [('state', 'in', ['cancelled', 'confirmed'])]}" groups="lunch.group_lunch_manager"/>
|
||||
<button name="action_reset" string="Reset" type="object" icon="fa-undo" attrs="{'invisible': [('state', '!=', 'cancelled')]}" groups="lunch.group_lunch_manager"/>
|
||||
@@ -134,7 +136,7 @@
|
||||
<field name="res_model">lunch.order</field>
|
||||
<field name="view_mode">tree,kanban,pivot</field>
|
||||
<field name="search_view_id" ref="lunch_order_view_search"/>
|
||||
<field name="context">{"search_default_is_mine":1, "search_default_group_by_date": 1}</field>
|
||||
<field name="context">{"search_default_is_mine":1, "search_default_group_by_date": 1, 'show_reorder_button': True}</field>
|
||||
<field name="help" type="html">
|
||||
<p class="o_view_nocontent_empty_folder">
|
||||
No previous order found
|
||||
|
||||
Reference in New Issue
Block a user