Browse Source

May 17: [FIX] Bug Fixed 'pos_book_order'

pull/320/head
RisvanaCybro 12 months ago
parent
commit
e142807c8b
  1. 3
      pos_book_order/__manifest__.py
  2. 5
      pos_book_order/doc/RELEASE_NOTES.md
  3. 17
      pos_book_order/models/book_order.py
  4. 17
      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. 6
      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': '16.0.1.0.1', 'version': '16.0.1.0.2',
'summary': """From a POS session, users can create pickup or 'summary': """From a POS session, users can create pickup or
delivery orders, which they can then confirm as POS orders.""", delivery orders, which they can then confirm as POS orders.""",
'description': """The module helps you to book orders from Shop, 'description': """The module helps you to book orders from Shop,
@ -47,6 +47,7 @@
'/pos_book_order/static/src/xml/BookedOrdersScreen.xml', '/pos_book_order/static/src/xml/BookedOrdersScreen.xml',
'/pos_book_order/static/src/xml/OrderReceipt.xml', '/pos_book_order/static/src/xml/OrderReceipt.xml',
'/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',

5
pos_book_order/doc/RELEASE_NOTES.md

@ -9,3 +9,8 @@
#### Version 16.0.1.0.1 #### Version 16.0.1.0.1
##### FIX ##### FIX
- Resolved the server error that occurs when creating the POS order. - Resolved the server error that occurs when creating the POS order.
-
#### 16.05.2024
#### Version 16.0.1.0.2
##### FIX
- Resolved issue of duplicating pos order.

17
pos_book_order/models/book_order.py

@ -94,6 +94,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 the order") help="Pricelist of the order")
pos_order_uid = fields.Char(help="Related Pos order",
string='Related Pos order')
@api.depends('book_line_ids.price_subtotal_incl', 'book_line_ids.discount') @api.depends('book_line_ids.price_subtotal_incl', 'book_line_ids.discount')
def _compute_amount_all(self): def _compute_amount_all(self):
@ -108,6 +110,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
@ -121,7 +130,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
@ -142,10 +151,11 @@ 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': [Command.create({ 'book_line_ids': [Command.create({
'product_id': product['product_id'][i], 'product_id': product['product_id'][i],
'qty': product['qty'][i], 'qty': product['qty'][i],
'price_unit':product['price'][i], 'price_unit': product['price'][i],
}) for i in range(len(product['product_id']))], }) for i in range(len(product['product_id']))],
'note': note, 'note': note,
}) })
@ -153,6 +163,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):
@ -167,7 +178,7 @@ class BookOrder(models.Model):
products.append({ products.append({
'id': line.product_id.id, 'id': line.product_id.id,
'qty': line.qty, 'qty': line.qty,
'price':line.price_unit 'price': line.price_unit
}) })
values.append({'id': rec.id, values.append({'id': rec.id,
'name': rec.name, 'name': rec.name,

17
pos_book_order/static/src/js/BookOrderPopup.js

@ -22,6 +22,7 @@ class BookOrderPopup extends AbstractAwaitablePopup {
var date = this.order.creation_date; var date = this.order.creation_date;
var line = this.order.orderlines; var line = this.order.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': [],
@ -32,11 +33,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
await this.rpc({
// this call for is creating a book order in the backend based on the value in popup // 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

@ -5,6 +5,8 @@
import Registries from 'point_of_sale.Registries'; import Registries from 'point_of_sale.Registries';
import TicketScreen from 'point_of_sale.TicketScreen'; import TicketScreen from 'point_of_sale.TicketScreen';
import {useListener} from "@web/core/utils/hooks"; import {useListener} from "@web/core/utils/hooks";
import { useService } from "@web/core/utils/hooks";
class BookedOrdersScreen extends TicketScreen { class BookedOrdersScreen extends TicketScreen {
setup() { setup() {
@ -12,28 +14,30 @@ 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 this.env.pos.add_new_order()
var data = ev.detail this.showScreen('ProductScreen');
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_partner(this.env.pos.db.get_partner_by_id(partner_id));
this.env.pos.selectedOrder.is_booked = true
this.env.pos.selectedOrder.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.orders.find((order) => order.uid == uid);
var partner_id = data.partner_id
this.env.pos.selectedOrder=order
this.env.pos.selectedOrder.is_booked = true
this.env.pos.selectedOrder.booked_data = data
this.env.pos.selectedOrder.booking_ref_id = data.id
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);
});

6
pos_book_order/static/src/xml/BookedOrdersScreen.xml

@ -5,10 +5,14 @@
<div class="partnerlist-screen screen"> <div class="partnerlist-screen screen">
<div class="screen-content"> <div class="screen-content">
<div class="top-content"> <div class="top-content">
<div class="button back" t-on-click="back"> <div class="button back" t-on-click="back" t-if="!props.new_order">
<i class="fa fa-angle-double-left"/> <i class="fa fa-angle-double-left"/>
Back Back
</div> </div>
<div class="button new" t-on-click="orderDone" t-if="props.new_order">
<i class="fa fa-plus"/>
New Order
</div>
</div> </div>
<section class="full-content"> <section class="full-content">
<div class="window"> <div class="window">

Loading…
Cancel
Save