[FIX] point_of_sale: demo last order preparation change

This PR resolves a bug in the self linked to the demo data.

Steps to reproduce:

Create a new Restaurant session
Open mobile menu for Restaurant
Make an order in the mobile menu for a table
Reload the page where the open restaurant session is.
[BUG] The ball telling if an order is sent to the kitchen or notbecame black.
[EXPECTATION] The ball telling if an order is sent to the kitchen or not is red.

closes odoo/odoo#134777

Signed-off-by: Robin Heinz (rhe) <rhe@odoo.com>
This commit is contained in:
Adrien Guilliams (adgu)
2023-09-21 16:52:09 +00:00
parent 3b3eb8f4db
commit b72b1950d5
7 changed files with 31 additions and 82 deletions
@@ -675,35 +675,5 @@
<function model="pos.session" name="action_pos_session_closing_control"
eval="[[ref('pos_closed_session_2')]]" />
<!-- Open Session -->
<record id="pos_open_session_1" model="pos.session" forcecreate="False">
<field name="config_id" ref="pos_config_main" />
<field name="user_id" ref="base.user_admin" />
</record>
<record id="pos_open_order_1" model="pos.order" forcecreate="False">
<field name="session_id" ref="pos_open_session_1" />
<field name="company_id" ref="base.main_company" />
<field name="name">Shop/00001</field>
<field name="state">draft</field>
<field name="amount_total">0.90</field>
<field name="amount_tax">0.0</field>
<field name="amount_paid">0.0</field>
<field name="amount_return">0.0</field>
<field name="pos_reference">Order 00001-001-0000</field>
<field name="partner_id" ref="base.res_partner_1" />
</record>
<record id="pos_orderline_1" model="pos.order.line" forcecreate="False">
<field name="name">Orderline 1</field>
<field name="product_id" ref="led_lamp" />
<field name="price_subtotal">0.90</field>
<field name="price_subtotal_incl">0.90</field>
<field name="price_unit">0.90</field>
<field name="order_id" ref="pos_open_order_1" />
<field name="full_product_name">LED Lamp</field>
</record>
</data>
</odoo>
</odoo>
@@ -1,34 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Open Session -->
<function model="ir.model.data" name="_update_xmlids">
<value model="base" eval="[{
'xml_id': 'point_of_sale.pos_open_session_1',
'record': obj().env.ref('point_of_sale.pos_config_main').current_session_id,
'noupdate': True,
}]" />
</function>
<record id="pos_open_order_1" model="pos.order" forcecreate="False">
<field name="session_id" ref="pos_open_session_1" />
<field name="company_id" ref="base.main_company" />
<field name="name">Shop/00001</field>
<field name="state">draft</field>
<field name="amount_total">0.90</field>
<field name="amount_tax">0.0</field>
<field name="amount_paid">0.0</field>
<field name="amount_return">0.0</field>
<field name="pos_reference">Order 00001-001-0000</field>
</record>
<record id="pos_orderline_1" model="pos.order.line" forcecreate="False">
<field name="name">Orderline 1</field>
<field name="product_id" ref="led_lamp" />
<field name="price_subtotal">0.90</field>
<field name="price_subtotal_incl">0.90</field>
<field name="price_unit">0.90</field>
<field name="order_id" ref="pos_open_order_1" />
<field name="full_product_name">LED Lamp</field>
</record>
</odoo>
@@ -2203,7 +2203,6 @@ class PosSession(models.Model):
'config_id': shop_config.id,
'user_id': self.env.ref('base.user_admin').id,
})
convert.convert_file(self.env, 'point_of_sale', 'data/point_of_sale_onboarding_open_session.xml', None, mode='init', kind='data')
def _after_load_onboarding_data(self):
config = self.env.ref('point_of_sale.pos_config_main', raise_if_not_found=False)
@@ -226,9 +226,10 @@ export class PosStore extends Reactive {
);
const { start_category, iface_start_categ_id } = this.config;
this.selectedCategoryId = (start_category && iface_start_categ_id?.[0]) || 0;
this.load_server_orders();
// Push orders in background, do not await
this.push_orders();
// This method is to load the demo datas.
this.load_server_orders();
this.markReady();
}
@@ -469,27 +470,18 @@ export class PosStore extends Reactive {
}
loadOpenOrders(openOrders) {
// This method is for the demo data
let isOrderSet = false;
for (const json of openOrders) {
if (this.orders.find((el) => el.server_id === json.id)) {
continue;
}
this._createOrder(json);
const newOrder = this.orders[this.orders.length - 1];
if (newOrder.orderlines[0].uuid) {
for (const line of newOrder.orderlines) {
newOrder.lastOrderPrepaChange[line.uuid + " - "] = {
line_uuid: line.uuid,
name: line.full_product_name,
note: "",
product_id: line.product.id,
quantity: line.quantity,
};
}
if (!isOrderSet) {
this.selectedOrder = this.orders[this.orders.length - 1];
isOrderSet = true;
}
}
if (openOrders.length > 0) {
this.selectedOrder = this.orders[1];
}
}
/**
@@ -871,5 +871,8 @@
<field name="order_id" ref="pos_open_order_5" />
<field name="full_product_name">Pizza 4 Formaggi</field>
</record>
<function model="pos.session" name="_set_last_order_preparation_change"
eval="[[ref('pos_open_order_2'), ref('pos_open_order_3'), ref('pos_open_order_4')]]"/>
</data>
</odoo>
</odoo>
@@ -148,4 +148,7 @@
<field name="order_id" ref="pos_open_order_5" />
<field name="full_product_name">Pizza 4 Formaggi</field>
</record>
<function model="pos.session" name="_set_last_order_preparation_change"
eval="[[ref('pos_open_order_2'), ref('pos_open_order_3'), ref('pos_open_order_4')]]"/>
</odoo>
@@ -5,6 +5,7 @@ from odoo import models, Command, api
from odoo.tools import convert
from itertools import groupby
from odoo.osv.expression import AND
import json
class PosSession(models.Model):
_inherit = 'pos.session'
@@ -81,3 +82,18 @@ class PosSession(models.Model):
'limit_categories': True,
'iface_available_categ_ids': [Command.link(self.env.ref('pos_restaurant.food').id), Command.link(self.env.ref('pos_restaurant.drinks').id)]
})
@api.model
def _set_last_order_preparation_change(self, order_ids):
for order_id in order_ids:
order = self.env['pos.order'].browse(order_id)
last_order_preparation_change = {}
for orderline in order['lines']:
last_order_preparation_change[orderline.uuid + " - "] = {
"line_uuid": orderline.uuid,
"name": orderline.full_product_name,
"note": "",
"product_id": orderline.product_id.id,
"quantity": orderline.qty,
}
order.write({'last_order_preparation_change': json.dumps(last_order_preparation_change)})