Compare commits

..

No commits in common. "19.0" and "17.0" have entirely different histories.
19.0 ... 17.0

3 changed files with 65 additions and 42 deletions

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*-
{
'name': 'POS Reverse Downpayment',
'version': '19.0.1.0.0',
'version': '1.0',
'category': 'Sales/Point of Sale',
'summary': 'Create Quotation from POS Cart and Zero-out Standard Items',
'description': """

View File

@ -77,6 +77,19 @@ class PosOrder(models.Model):
pickings = self.env['stock.picking']._create_picking_from_pos_order_lines(destination_id, lines_to_pick, picking_type, self.partner_id)
pickings.write({'pos_session_id': self.session_id.id, 'pos_order_id': self.id, 'origin': self.name})
def _process_preparation_changes(self, cancelled=False, note_history=None):
"""
Intercepts preparation display generation. If this POS order is actually a Quotation
we don't want it to be processed by the kitchen display.
"""
if any(line.is_quotation_line for line in self.lines):
return {'change': False, 'sound': False, 'category_ids': []}
# Check if pos_preparation_display is installed and we can call super
if hasattr(super(), '_process_preparation_changes'):
return super()._process_preparation_changes(cancelled=cancelled, note_history=note_history)
return {'change': False, 'sound': False, 'category_ids': []}
class PosOrderLine(models.Model):
_inherit = 'pos.order.line'
@ -86,8 +99,14 @@ class PosOrderLine(models.Model):
default=False
)
@api.model
def _load_pos_data_fields(self, config):
result = super()._load_pos_data_fields(config)
result.append('is_quotation_line')
def _export_for_ui(self, orderline):
result = super()._export_for_ui(orderline)
result['is_quotation_line'] = orderline.is_quotation_line
return result
def _order_line_fields(self, line, session_id=None):
result = super()._order_line_fields(line, session_id)
if 'is_quotation_line' in line[2]:
result[2]['is_quotation_line'] = line[2]['is_quotation_line']
return result

View File

@ -1,7 +1,6 @@
/** @odoo-module */
import { PosStore } from "@point_of_sale/app/services/pos_store";
import { PosOrderline } from "@point_of_sale/app/models/pos_order_line";
import { Order, Orderline } from "@point_of_sale/app/store/models";
import { patch } from "@web/core/utils/patch";
import { ConfirmPopup } from "@point_of_sale/app/utils/confirm_popup/confirm_popup";
import { ErrorPopup } from "@point_of_sale/app/errors/popups/error_popup";
@ -9,38 +8,35 @@ import { _t } from "@web/core/l10n/translation";
import { OrderReceipt } from "@point_of_sale/app/screens/receipt_screen/receipt/order_receipt";
import { onError } from "@odoo/owl";
PosOrderline.extraFields.push("is_quotation_line");
patch(Order.prototype, {
setup() {
super.setup(...arguments);
},
patch(PosStore.prototype, {
async pay() {
const order = this.getOrder();
if (!order) {
return super.pay(...arguments);
}
// Check if down payment product is in the cart
const downPaymentProductId = this.config.down_payment_product_id && this.config.down_payment_product_id[0];
const downPaymentProductId = this.pos.config.down_payment_product_id && this.pos.config.down_payment_product_id[0];
if (!downPaymentProductId) {
return super.pay(...arguments);
}
const lines = order.lines;
const lines = this.get_orderlines();
// Only consider it a "quotation creation" downpayment if it has a positive quantity and price.
// If pos_sale adds it to deduct a downpayment, it will use negative qty or subtotal.
const downPaymentLines = lines.filter(line =>
line.product_id.id === downPaymentProductId &&
line.qty > 0 &&
line.price_unit >= 0
line.product.id === downPaymentProductId &&
line.get_quantity() > 0 &&
line.get_unit_price() >= 0
);
const standardLines = lines.filter(line => line.product_id.id !== downPaymentProductId);
const standardLines = lines.filter(line => line.product.id !== downPaymentProductId);
// If there is a down payment, we require a customer and automatically
// create a quotation without prompting.
const needsQuotation = downPaymentLines.length > 0;
if (needsQuotation && !order.is_quotation_line_converted) {
if (!order.partner_id) {
if (needsQuotation && !this.is_quotation_line_converted) {
if (!this.get_partner()) {
await this.env.services.popup.add(ErrorPopup, {
title: _t("Customer Required"),
body: _t("Please select a customer before creating a quotation with a down payment."),
@ -51,23 +47,23 @@ patch(PosStore.prototype, {
try {
// Prepare data for backend
const linesData = standardLines.map(line => ({
product_id: line.product_id.id,
qty: line.qty,
price_unit: line.price_unit,
discount: line.discount,
tax_ids: line.tax_ids ? line.tax_ids.map(t => t.id) : [],
product_id: line.product.id,
qty: line.get_quantity(),
price_unit: line.get_unit_price(),
discount: line.get_discount(),
tax_ids: line.tax_ids || line.get_product().taxes_id || [],
}));
// Call backend to create sale.order
// Call backend to create sale.order (removed the first empty array for @api.model)
const saleOrderResult = await this.env.services.orm.call(
"pos.order",
"create_quotation_from_pos_lines",
[order.partner_id.id, linesData, this.config.id]
[this.get_partner().id, linesData, this.pos.config.id]
);
if (saleOrderResult) {
// Link the down payment line to the newly created sale order
const dpLine = lines.find(line => line.product_id.id === downPaymentProductId);
const dpLine = lines.find(line => line.product.id === downPaymentProductId);
if (dpLine) {
dpLine.sale_order_origin_id = {
id: saleOrderResult.id,
@ -77,11 +73,11 @@ patch(PosStore.prototype, {
// Zero out the standard lines to not charge the customer twice
for (const line of standardLines) {
line.setUnitPrice(0);
line.set_unit_price(0);
// Set a flag to easily skip stock delivery later if needed
line.is_quotation_line = true;
}
order.is_quotation_line_converted = true;
this.is_quotation_line_converted = true;
} else {
await this.env.services.popup.add(ErrorPopup, {
title: _t("Error"),
@ -103,20 +99,28 @@ patch(PosStore.prototype, {
// Override preparation display / kitchen printing
// If we have a down payment, we consider this a quote, not an immediate order for the kitchen
async sendOrderInPreparationUpdateLastChange(order, opts = {}) {
const downPaymentProductId = this.config.down_payment_product_id && this.config.down_payment_product_id[0];
async sendChanges(cancelled) {
const downPaymentProductId = this.pos.config.down_payment_product_id && this.pos.config.down_payment_product_id[0];
// Only block if there's a positive down payment line (indicating quotation creation, not settlement)
if (downPaymentProductId && order.lines.some(line => line.product_id.id === downPaymentProductId && line.qty > 0 && line.price_unit > 0)) {
if (downPaymentProductId && this.get_orderlines().some(line => line.product.id === downPaymentProductId && line.get_quantity() > 0 && line.get_unit_price() > 0)) {
// It's a quotation line, we don't send it to preparation display
order.noteHistory = {};
order.lines.forEach(line => {
if(line.uiState) {
line.uiState.hasChange = false;
}
});
this.noteHistory = {};
this.orderlines.forEach(line => line.setHasChange(false));
return true;
}
return super.sendOrderInPreparationUpdateLastChange(...arguments);
return super.sendChanges(...arguments);
}
});
patch(Orderline.prototype, {
init_from_JSON(json) {
super.init_from_JSON(...arguments);
this.is_quotation_line = json.is_quotation_line || false;
},
export_as_JSON() {
const json = super.export_as_JSON(...arguments);
json.is_quotation_line = this.is_quotation_line || false;
return json;
}
});