Browse Source

May 18: [FIX] Bug Fixed 'pos_book_order'

pull/254/merge
RisvanaCybro 11 months ago
parent
commit
b38bf0857e
  1. 3
      pos_book_order/__manifest__.py
  2. 8
      pos_book_order/doc/RELEASE_NOTES.md
  3. 14
      pos_book_order/models/book_order.py
  4. 22
      pos_book_order/static/src/js/BookOrderPopup.js
  5. 3
      pos_book_order/static/src/js/BookedOrdersButton.js
  6. 42
      pos_book_order/static/src/js/BookedOrdersScreen.js
  7. 39
      pos_book_order/static/src/js/Ticketscreen.js
  8. 9
      pos_book_order/static/src/xml/BookedOrdersScreen.xml

3
pos_book_order/__manifest__.py

@ -21,7 +21,7 @@
############################################################################### ###############################################################################
{ {
'name': 'POS Booking Order', '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 'summary': """Users can now book pickup or delivery orders directly
from the Point of Sale (POS) session, later can confirm as POS order.""", from the Point of Sale (POS) session, later can confirm as POS order.""",
'description': """The module helps you to book orders from Shop, 'description': """The module helps you to book orders from Shop,
@ -43,6 +43,7 @@
'assets': { 'assets': {
'point_of_sale.assets': [ 'point_of_sale.assets': [
'/pos_book_order/static/src/js/BookOrderPopup.js', '/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/BookOrderButton.js',
'/pos_book_order/static/src/js/BookedOrdersButton.js', '/pos_book_order/static/src/js/BookedOrdersButton.js',
'/pos_book_order/static/src/js/BookedOrdersScreen.js', '/pos_book_order/static/src/js/BookedOrdersScreen.js',

8
pos_book_order/doc/RELEASE_NOTES.md

@ -3,4 +3,10 @@
#### 26.06.2023 #### 26.06.2023
#### Version 15.0.1.0.0 #### Version 15.0.1.0.0
##### ADD ##### ADD
- Initial Commit for POS Booking Order - Initial Commit for POS Booking Order
-
#### 17.05.2024
#### Version 15.0.1.0.1
##### FIX
- Resolved issue of duplicating pos order.

14
pos_book_order/models/book_order.py

@ -74,7 +74,8 @@ class BookOrder(models.Model):
help='Address of customer for delivery') help='Address of customer for delivery')
pricelist_id = fields.Many2one('product.pricelist', string='Pricelist', pricelist_id = fields.Many2one('product.pricelist', string='Pricelist',
help="Pricelist of order from session") help="Pricelist of order from session")
pos_order_uid = fields.Char(help="Related Pos order",
string='Related Pos order')
@api.model @api.model
def _amount_line_tax(self, line, fiscal_position_id): def _amount_line_tax(self, line, fiscal_position_id):
""" Calculates the tax amount of the order line""" """ 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)) sum(line.price_subtotal for line in order.book_line_ids))
order.amount_total = order.amount_tax + amount_untaxed 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 @api.model
def create(self, vals): def create(self, vals):
""" Inherited create function to generate sequence number """ Inherited create function to generate sequence number
@ -115,7 +123,7 @@ class BookOrder(models.Model):
@api.model @api.model
def create_booked_order(self, partner, phone, address, date, price_list, 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 """ It creates a booked order based on the value in the booking popup
in PoS ui. in PoS ui.
partner(int): id of partner partner(int): id of partner
@ -136,6 +144,7 @@ class BookOrder(models.Model):
'delivery_address': address, 'delivery_address': address,
'pricelist_id': price_list, 'pricelist_id': price_list,
'date_quotation': book_date, 'date_quotation': book_date,
'pos_order_uid': pos_order_uid,
'book_line_ids': [(0, 0, { 'book_line_ids': [(0, 0, {
'product_id': product['product_id'][i], 'product_id': product['product_id'][i],
'qty': product['qty'][i], 'qty': product['qty'][i],
@ -147,6 +156,7 @@ class BookOrder(models.Model):
order.write({'pickup_date': pickup + ' 00:00:00'}) order.write({'pickup_date': pickup + ' 00:00:00'})
if delivery: if delivery:
order.write({'deliver_date': delivery + ' 00:00:00'}) order.write({'deliver_date': delivery + ' 00:00:00'})
return order.name
@api.model @api.model
def all_orders(self): def all_orders(self):

22
pos_book_order/static/src/js/BookOrderPopup.js

@ -10,7 +10,8 @@ import {Gui} from 'point_of_sale.Gui';
class BookOrderPopup extends AbstractAwaitablePopup { class BookOrderPopup extends AbstractAwaitablePopup {
setup() { setup() {
super.setup() super.setup()
this.order = this.env.pos.get_order() this.order = this.env.pos.get_order();
} }
async onConfirm() { async onConfirm() {
// On clicking confirm button of popup a new book order with draft stage will created from the backend // 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 date = this.order.creation_date;
var line = this.order.get_orderlines(); var line = this.order.get_orderlines();
var price_list = this.order.pricelist.id; var price_list = this.order.pricelist.id;
var uid = this.order.uid;
var product = { var product = {
'product_id': [], 'product_id': [],
'qty': [], 'qty': [],
@ -33,11 +35,23 @@ class BookOrderPopup extends AbstractAwaitablePopup {
product['qty'].push(line[i].quantity) product['qty'].push(line[i].quantity)
product['price'].push(line[i].price) product['price'].push(line[i].price)
}; };
await rpc.query({ var self = this
// This call for is creating a book order in the backend based on the value in popup await this.rpc({
// this call for is creating a book order in the backend based on the value in popup
model: 'book.order', model: 'book.order',
method: 'create_booked_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(); this.cancel();
} }

3
pos_book_order/static/src/js/BookedOrdersButton.js

@ -16,7 +16,8 @@ class BookedOrdersButton extends PosComponent {
method: 'all_orders', method: 'all_orders',
}).then(function(result) { }).then(function(result) {
self.showScreen('BookedOrdersScreen', { self.showScreen('BookedOrdersScreen', {
data: result data: result,
new_order: false,
}); });
}) })
} }

42
pos_book_order/static/src/js/BookedOrdersScreen.js

@ -12,28 +12,32 @@ class BookedOrdersScreen extends TicketScreen {
useListener('click-confirm', this._Confirm); useListener('click-confirm', this._Confirm);
} }
back() { back() {
// on clicking the back button it will redirected Product screen
this.showScreen('ProductScreen'); this.showScreen('ProductScreen');
} }
_Confirm(ev) { orderDone() {
// On clicking confirm button on each order a order will create with corresponding partner and products,user can do the payment // on clicking the back button it will redirected Product screen
var self = this const newOrder = this.env.pos.add_new_order();
var data = ev.detail this.env.pos.set_order(newOrder);
this.env.pos.add_new_order(); this.showScreen('ProductScreen');
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');
} }
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'; BookedOrdersScreen.template = 'BookedOrdersScreen';
Registries.Component.add(BookedOrdersScreen); Registries.Component.add(BookedOrdersScreen);

39
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);
});

9
pos_book_order/static/src/xml/BookedOrdersScreen.xml

@ -7,7 +7,7 @@
<div class="rightpane pane-border"> <div class="rightpane pane-border">
<div class="controls"> <div class="controls">
<t t-if="!env.isMobile"> <t t-if="!env.isMobile">
<div class="buttons"> <div class="buttons" t-if="!props.new_order">
<button class="discard" <button class="discard"
t-on-click="trigger('close-screen')"> t-on-click="trigger('close-screen')">
<span class="search-icon"> <span class="search-icon">
@ -18,6 +18,13 @@
</t> </t>
</button> </button>
</div> </div>
<div class="buttons">
<div class="button new" t-on-click="orderDone"
t-if="props.new_order">
<i class="fa fa-plus"/>
New Order
</div>
</div>
</t> </t>
</div> </div>
<div class="orders"> <div class="orders">

Loading…
Cancel
Save