diff --git a/pos_book_order/__manifest__.py b/pos_book_order/__manifest__.py index c809e47f1..06f29ac2a 100644 --- a/pos_book_order/__manifest__.py +++ b/pos_book_order/__manifest__.py @@ -21,7 +21,7 @@ ############################################################################### { 'name': 'POS Booking Order', - 'version': '15.0.1.0.0', + 'version': '15.0.1.0.1', 'summary': """Users can now book pickup or delivery orders directly from the Point of Sale (POS) session, later can confirm as POS order.""", 'description': """The module helps you to book orders from Shop, @@ -43,6 +43,7 @@ 'assets': { 'point_of_sale.assets': [ '/pos_book_order/static/src/js/BookOrderPopup.js', + '/pos_book_order/static/src/js/Ticketscreen.js', '/pos_book_order/static/src/js/BookOrderButton.js', '/pos_book_order/static/src/js/BookedOrdersButton.js', '/pos_book_order/static/src/js/BookedOrdersScreen.js', diff --git a/pos_book_order/doc/RELEASE_NOTES.md b/pos_book_order/doc/RELEASE_NOTES.md index 5db95d8a0..d3d24a51b 100644 --- a/pos_book_order/doc/RELEASE_NOTES.md +++ b/pos_book_order/doc/RELEASE_NOTES.md @@ -3,4 +3,10 @@ #### 26.06.2023 #### Version 15.0.1.0.0 ##### ADD -- Initial Commit for POS Booking Order \ No newline at end of file +- Initial Commit for POS Booking Order + +- +#### 17.05.2024 +#### Version 15.0.1.0.1 +##### FIX +- Resolved issue of duplicating pos order. \ No newline at end of file diff --git a/pos_book_order/models/book_order.py b/pos_book_order/models/book_order.py index 2cc809c6f..e9479eb47 100644 --- a/pos_book_order/models/book_order.py +++ b/pos_book_order/models/book_order.py @@ -74,7 +74,8 @@ class BookOrder(models.Model): help='Address of customer for delivery') pricelist_id = fields.Many2one('product.pricelist', string='Pricelist', help="Pricelist of order from session") - + pos_order_uid = fields.Char(help="Related Pos order", + string='Related Pos order') @api.model def _amount_line_tax(self, line, fiscal_position_id): """ Calculates the tax amount of the order line""" @@ -102,6 +103,13 @@ class BookOrder(models.Model): sum(line.price_subtotal for line in order.book_line_ids)) order.amount_total = order.amount_tax + amount_untaxed + def action_confirm(self): + """ Function to confirm the book order""" + self.write({ + 'state': 'confirmed', + }) + return self.pos_order_uid + @api.model def create(self, vals): """ Inherited create function to generate sequence number @@ -115,7 +123,7 @@ class BookOrder(models.Model): @api.model def create_booked_order(self, partner, phone, address, date, price_list, - product, note, pickup, delivery): + product, note, pickup, delivery, pos_order_uid): """ It creates a booked order based on the value in the booking popup in PoS ui. partner(int): id of partner @@ -136,6 +144,7 @@ class BookOrder(models.Model): 'delivery_address': address, 'pricelist_id': price_list, 'date_quotation': book_date, + 'pos_order_uid': pos_order_uid, 'book_line_ids': [(0, 0, { 'product_id': product['product_id'][i], 'qty': product['qty'][i], @@ -147,6 +156,7 @@ class BookOrder(models.Model): order.write({'pickup_date': pickup + ' 00:00:00'}) if delivery: order.write({'deliver_date': delivery + ' 00:00:00'}) + return order.name @api.model def all_orders(self): diff --git a/pos_book_order/static/src/js/BookOrderPopup.js b/pos_book_order/static/src/js/BookOrderPopup.js index 3e4687ca9..36e4c73c6 100644 --- a/pos_book_order/static/src/js/BookOrderPopup.js +++ b/pos_book_order/static/src/js/BookOrderPopup.js @@ -10,7 +10,8 @@ import {Gui} from 'point_of_sale.Gui'; class BookOrderPopup extends AbstractAwaitablePopup { setup() { super.setup() - this.order = this.env.pos.get_order() + this.order = this.env.pos.get_order(); + } async onConfirm() { // On clicking confirm button of popup a new book order with draft stage will created from the backend @@ -23,6 +24,7 @@ class BookOrderPopup extends AbstractAwaitablePopup { var date = this.order.creation_date; var line = this.order.get_orderlines(); var price_list = this.order.pricelist.id; + var uid = this.order.uid; var product = { 'product_id': [], 'qty': [], @@ -33,11 +35,23 @@ class BookOrderPopup extends AbstractAwaitablePopup { product['qty'].push(line[i].quantity) product['price'].push(line[i].price) }; - await rpc.query({ - // This call for is creating a book order in the backend based on the value in popup + var self = this + await this.rpc({ + // this call for is creating a book order in the backend based on the value in popup model: 'book.order', method: 'create_booked_order', - args: [partner, phone, address, date, price_list, product, order_note, pickup_date, delivery_date] + args: [partner, phone, address, date, price_list, product, order_note, pickup_date, delivery_date,uid] + }).then(function(book_order) { + self.order.booking_ref_id=book_order + }) + await this.rpc({ + model: 'book.order', + method: 'all_orders', + }).then(function(result) { + self.showScreen('BookedOrdersScreen', { + data: result, + new_order: true, + }); }) this.cancel(); } diff --git a/pos_book_order/static/src/js/BookedOrdersButton.js b/pos_book_order/static/src/js/BookedOrdersButton.js index 63a4369f8..859cae910 100644 --- a/pos_book_order/static/src/js/BookedOrdersButton.js +++ b/pos_book_order/static/src/js/BookedOrdersButton.js @@ -16,7 +16,8 @@ class BookedOrdersButton extends PosComponent { method: 'all_orders', }).then(function(result) { self.showScreen('BookedOrdersScreen', { - data: result + data: result, + new_order: false, }); }) } diff --git a/pos_book_order/static/src/js/BookedOrdersScreen.js b/pos_book_order/static/src/js/BookedOrdersScreen.js index 17d420391..c1f037a1d 100644 --- a/pos_book_order/static/src/js/BookedOrdersScreen.js +++ b/pos_book_order/static/src/js/BookedOrdersScreen.js @@ -12,28 +12,32 @@ class BookedOrdersScreen extends TicketScreen { useListener('click-confirm', this._Confirm); } back() { - // on clicking the back button it will redirected Product screen this.showScreen('ProductScreen'); } - _Confirm(ev) { - // On clicking confirm button on each order a order will create with corresponding partner and products,user can do the payment - var self = this - var data = ev.detail - this.env.pos.add_new_order(); - for (var i of data.products) { - var product = self.env.pos.db.get_product_by_id(i['id']) - var qty = i['qty'] - this.env.pos.get_order().add_product(product, { - quantity: qty, - price: i['price'] - }) - } - var partner_id = data.partner_id - this.env.pos.get_order().set_client(this.env.pos.db.get_partner_by_id(partner_id)); - this.env.pos.get_order().is_booked = true - this.env.pos.get_order().booked_data = data - this.showScreen('ProductScreen'); + orderDone() { + // on clicking the back button it will redirected Product screen + const newOrder = this.env.pos.add_new_order(); + this.env.pos.set_order(newOrder); + this.showScreen('ProductScreen'); } + async _Confirm(ev) { + // On clicking confirm button on each order a order will create with corresponding partner and products,user can do the payment + var self = this + var data = ev.detail + var uid = await this.rpc({ + model: 'book.order', + method: 'action_confirm', + args: [data.id] + }) + var order = this.env.pos.get('orders').models.find((order) => order.uid == uid); + var partner_id = data.partner_id + order.is_booked = true + order.booked_data = data + order.booking_ref_id = data.id + this.env.pos.set_order(order); + + this.showScreen('ProductScreen'); +} } BookedOrdersScreen.template = 'BookedOrdersScreen'; Registries.Component.add(BookedOrdersScreen); \ No newline at end of file diff --git a/pos_book_order/static/src/js/Ticketscreen.js b/pos_book_order/static/src/js/Ticketscreen.js new file mode 100644 index 000000000..36ce6fdf7 --- /dev/null +++ b/pos_book_order/static/src/js/Ticketscreen.js @@ -0,0 +1,39 @@ +odoo.define('pos_book_order.TicketScreen', function (require) { + 'use strict'; + + const PosComponent = require('point_of_sale.PosComponent'); + const TicketScreen = require('point_of_sale.TicketScreen'); + const Registries = require('point_of_sale.Registries'); + const { useAutofocus } = require("@web/core/utils/hooks"); + const { parse } = require('web.field_utils'); + const { useState } = owl; + + const BookOrderTicketScreen = (TicketScreen) => + class extends TicketScreen { + async _onClickOrder({ detail: clickedOrder }) { + if (clickedOrder.booking_ref_id && !clickedOrder.is_paid()){ + const {confirmed} = await this.showPopup('ConfirmPopup', { + title: this.env._t('Confirm Booking'), + body: this.env._t('You have to confirm the booking to choose this order'), + }); + if (confirmed) { + var self = this + await this.rpc({ + model: 'book.order', + method: 'all_orders', + }).then(function(result) { + self.showScreen('BookedOrdersScreen', { + data: result, + new_order: false, + }); + }) + } + } + else{ + return super._onClickOrder({ detail: clickedOrder }); + } + } + }; + + Registries.Component.extend(TicketScreen, BookOrderTicketScreen); +}); diff --git a/pos_book_order/static/src/xml/BookedOrdersScreen.xml b/pos_book_order/static/src/xml/BookedOrdersScreen.xml index ccfbe3a91..884447079 100644 --- a/pos_book_order/static/src/xml/BookedOrdersScreen.xml +++ b/pos_book_order/static/src/xml/BookedOrdersScreen.xml @@ -7,7 +7,7 @@