Skip to content

Commit

Permalink
[IMP] point_of_sale: load default demo data
Browse files Browse the repository at this point in the history
When loading the pos without demo data, before we had a wizard that allowed the user to load data before the pos starts.
Now, we let the user go to the frontend without preloading products and categories in the database.
In the front end, when no products and categories are loaded, we let the user press buttons to load the default products and categories.

The user can also be redirected to the back end to add new products.

closes odoo#117823

Task-id: 3054477
Related: odoo/upgrade#4523
Signed-off-by: Samuel Degueldre <[email protected]>
  • Loading branch information
rhe-odoo authored and sdegueldre committed May 12, 2023
1 parent 8b64f9d commit 5e55758
Show file tree
Hide file tree
Showing 11 changed files with 59 additions and 56 deletions.
1 change: 0 additions & 1 deletion addons/point_of_sale/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
'wizard/pos_details.xml',
'wizard/pos_payment.xml',
'wizard/pos_close_session_wizard.xml',
'wizard/pos_session_check_product_wizard.xml',
'wizard/pos_daily_sales_reports.xml',
'views/pos_assets_index.xml',
'views/pos_assets_qunit.xml',
Expand Down
6 changes: 6 additions & 0 deletions addons/point_of_sale/data/point_of_sale_data.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
<field name="params" eval="{'menu_id': ref('menu_point_root')}"/>
</record>

<record id="action_client_product_menu" model="ir.actions.client">
<field name="name">Load Product Menu</field>
<field name="tag">reload</field>
<field name="params" eval="{'menu_id': ref('point_of_sale.menu_pos_products')}"/>
</record>

<function model="stock.warehouse" name="_create_missing_pos_picking_types"/>

<record id="product_category_pos" model="product.category">
Expand Down
14 changes: 0 additions & 14 deletions addons/point_of_sale/models/pos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,20 +527,6 @@ def open_ui(self):
self._check_before_creating_new_session()
self._validate_fields(self._fields)

# check if there's any product for this PoS
domain = [('available_in_pos', '=', True)]
if self.limit_categories and self.iface_available_categ_ids:
domain.append(('pos_categ_id', 'in', self.iface_available_categ_ids.ids))
if not self.env['product.product'].search(domain):
return {
'name': _("There is no product linked to your PoS"),
'type': 'ir.actions.act_window',
'view_mode': 'form',
'res_model': 'pos.session.check_product_wizard',
'target': 'new',
'context': {'config_id': self.id}
}

return self._action_to_open_ui()

def open_existing_session_cb(self):
Expand Down
8 changes: 7 additions & 1 deletion addons/point_of_sale/models/pos_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from odoo import api, fields, models, _, Command
from odoo.exceptions import AccessError, UserError, ValidationError
from odoo.tools import float_is_zero, float_compare
from odoo.tools import float_is_zero, float_compare, convert
from odoo.osv.expression import AND, OR
from odoo.service.common import exp_version

Expand Down Expand Up @@ -2125,6 +2125,12 @@ def get_pos_ui_account_fiscal_positions_by_ids(self, fp_ids):

return fps

def load_product_frontend(self):
convert.convert_file(self.env, 'point_of_sale', 'data/point_of_sale_onboarding.xml', None, mode='init',
kind='data')
return self.get_onboarding_data()


class ProcurementGroup(models.Model):
_inherit = 'procurement.group'

Expand Down
1 change: 0 additions & 1 deletion addons/point_of_sale/security/ir.model.access.csv
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,4 @@ access_pos_make_payment,access.pos.make.payment,model_pos_make_payment,point_of_
access_pos_close_session_wizard,access.pos.close.session.wizard,model_pos_close_session_wizard,point_of_sale.group_pos_user,1,1,1,0
access_account_cash_rounding_pos_user,account.cash.rounding pos_user,account.model_account_cash_rounding,group_pos_user,1,0,0,0
access_pos_bill,pos.bill pos_user,model_pos_bill,group_pos_user,1,1,1,1
access_pos_session_check_product_wizard,access.pos.session.check.product.wizard,model_pos_session_check_product_wizard,group_pos_user,1,1,1,0
access_pos_daily_sales_reports_wizard,access.pos.daily.sales.reports.wizard,model_pos_daily_sales_reports_wizard,group_pos_manager,1,1,1,0
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,19 @@ export class ProductsWidget extends Component {
*/
setup() {
super.setup();
this.state = useState({ previousSearchWord: "", currentOffset: 0 });
this.state = useState({
previousSearchWord: "",
currentOffset: 0,
showReloadMessage: false,
});
this.pos = usePos();
this.popup = useService("popup");
this.notification = useService("pos_notification");
this.orm = useService("orm");
}
get hasProducts() {
return Object.keys(this.pos.globalState.db.product_by_id).length > 0;
}
get selectedCategoryId() {
return this.env.pos.selectedCategoryId;
}
Expand Down Expand Up @@ -161,4 +168,18 @@ export class ProductsWidget extends Component {
}
}
}
async loadDemoDataProducts() {
const { products, categories } = await this.orm.call(
"pos.session",
"load_product_frontend",
[this.pos.globalState.pos_session.id]
);
this.pos.globalState.db.add_categories(categories);
this.pos.globalState._loadProductProduct(products);
}

createNewProducts() {
window.open("/web#action=point_of_sale.action_client_product_menu", "_blank");
this.state.showReloadMessage = true;
}
}
17 changes: 17 additions & 0 deletions addons/point_of_sale/static/src/scss/pos.scss
Original file line number Diff line number Diff line change
Expand Up @@ -3600,6 +3600,23 @@ td {
background: rgba(104,69,95, 0.7);
}

.pos .no-results-message .button-no-demo {
margin: 3px;
width: 180px;
padding: 10px 0;
cursor: pointer;
font-size: large;
}

.info-load-product-message {
background: lightblue;
color: #017e84;
padding: 8px;
width: fit-content;
display: block;
margin : 3px auto 0 auto;
}

@media screen and (max-width: 768px) {
.pos .search-bar-container.sb-product {
max-width: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
<p t-else="">
There are no products in this category.
</p>
<div t-if="!hasProducts">
<button class="button-no-demo" t-on-click="loadDemoDataProducts">Generate demo data</button>
<button class="button-no-demo" t-on-click="createNewProducts">Create new products</button>
<div t-if="state.showReloadMessage" class="info-load-product-message">
Please reload this page once products have been created
</div>
</div>
</div>
<div t-if="searchWord" class="search-more-button">
<div class="button" t-on-click="onPressEnterKey">Search more</div>
Expand Down
1 change: 0 additions & 1 deletion addons/point_of_sale/wizard/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@
from . import pos_details
from . import pos_payment
from . import pos_close_session_wizard
from . import pos_session_check_product_wizard
from . import pos_daily_sales_reports
18 changes: 0 additions & 18 deletions addons/point_of_sale/wizard/pos_session_check_product_wizard.py

This file was deleted.

19 changes: 0 additions & 19 deletions addons/point_of_sale/wizard/pos_session_check_product_wizard.xml

This file was deleted.

0 comments on commit 5e55758

Please sign in to comment.