Skip to content

[16.0][IMP]pos_order_to_sale_order: Allow add the commitment date. #1361

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: 16.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions pos_order_to_sale_order/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ Contributors

* Sylvain LE GAL (https://www.twitter.com/legalsylvain)

* `Binhex <https://binhex.cloud>`_:

* Adasat Torres de León <[email protected]>

Maintainers
~~~~~~~~~~~

Expand Down
8 changes: 3 additions & 5 deletions pos_order_to_sale_order/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@
"data": ["views/view_res_config_settings.xml"],
"assets": {
"point_of_sale.assets": [
"pos_order_to_sale_order/static/src/css/pos.css",
"pos_order_to_sale_order/static/src/js/CreateOrderButton.js",
"pos_order_to_sale_order/static/src/js/CreateOrderPopup.js",
"pos_order_to_sale_order/static/src/xml/CreateOrderButton.xml",
"pos_order_to_sale_order/static/src/xml/CreateOrderPopup.xml",
"pos_order_to_sale_order/static/src/css/**.css",
"pos_order_to_sale_order/static/src/xml/**.xml",
"pos_order_to_sale_order/static/src/js/**.js",
],
"web.assets_tests": [
"pos_order_to_sale_order/static/tests/**/*.js",
Expand Down
7 changes: 7 additions & 0 deletions pos_order_to_sale_order/models/pos_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,13 @@ class PosConfig(models.Model):
" Only invoice payment process will be possible.",
)

iface_sale_order_allow_commitment_date = fields.Boolean(
string="Allow Add Commitment Date",
default=True,
help="If checked, the cashier will have the possibility to add"
" a commitment date on the sale order.",
)

@api.depends(
"iface_create_draft_sale_order",
"iface_create_confirmed_sale_order",
Expand Down
4 changes: 4 additions & 0 deletions pos_order_to_sale_order/models/res_config_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,7 @@ class ResConfigSettings(models.TransientModel):
pos_iface_create_invoiced_sale_order = fields.Boolean(
related="pos_config_id.iface_create_invoiced_sale_order", readonly=False
)

iface_sale_order_allow_commitment_date = fields.Boolean(
related="pos_config_id.iface_sale_order_allow_commitment_date", readonly=False
)
9 changes: 9 additions & 0 deletions pos_order_to_sale_order/models/sale_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from datetime import datetime

from odoo import Command, _, api, models


Expand All @@ -17,13 +19,20 @@
Command.create(SaleOrderLine._prepare_from_pos(sequence, line_data[2]))
for sequence, line_data in enumerate(order_data["lines"], start=1)
]
if order_data.get("commitment_date", False):
commitment_date = datetime.strptime(

Check warning on line 23 in pos_order_to_sale_order/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

pos_order_to_sale_order/models/sale_order.py#L23

Added line #L23 was not covered by tests
order_data["commitment_date"], "%Y-%m-%dT%H:%M:%S.%fZ"
)
else:
commitment_date = False

Check warning on line 27 in pos_order_to_sale_order/models/sale_order.py

View check run for this annotation

Codecov / codecov/patch

pos_order_to_sale_order/models/sale_order.py#L27

Added line #L27 was not covered by tests
return {
"partner_id": order_data["partner_id"],
"origin": _("Point of Sale %s") % (session.name),
"client_order_ref": order_data["name"],
"user_id": order_data["user_id"],
"pricelist_id": order_data["pricelist_id"],
"fiscal_position_id": order_data["fiscal_position_id"],
"commitment_date": commitment_date,
"order_line": order_lines,
}

Expand Down
4 changes: 4 additions & 0 deletions pos_order_to_sale_order/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
* Sylvain LE GAL (https://www.twitter.com/legalsylvain)

* `Binhex <https://binhex.cloud>`_:

* Adasat Torres de León <[email protected]>
4 changes: 4 additions & 0 deletions pos_order_to_sale_order/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,10 @@ <h2><a class="toc-backref" href="#toc-entry-6">Authors</a></h2>
<h2><a class="toc-backref" href="#toc-entry-7">Contributors</a></h2>
<ul class="simple">
<li>Sylvain LE GAL (<a class="reference external" href="https://www.twitter.com/legalsylvain">https://www.twitter.com/legalsylvain</a>)</li>
<li><a class="reference external" href="https://binhex.cloud">Binhex</a>:<ul>
<li>Adasat Torres de León &lt;<a class="reference external" href="mailto:a.torres&#64;binhex.cloud">a.torres&#64;binhex.cloud</a>&gt;</li>
</ul>
</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
16 changes: 10 additions & 6 deletions pos_order_to_sale_order/static/src/js/CreateOrderPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@ odoo.define("point_of_sale.CreateOrderPopup", function (require) {
const AbstractAwaitablePopup = require("point_of_sale.AbstractAwaitablePopup");
const Registries = require("point_of_sale.Registries");
const framework = require("web.framework");

class CreateOrderPopup extends AbstractAwaitablePopup {
setup() {
super.setup();
this.createOrderClicked = false;
}

get currentOrder() {
return this.env.pos.get_order();
}

async updateCommitmentDate(ev) {
await this.currentOrder.set_commitment_date(ev.target.value);
}

async createDraftSaleOrder() {
await this._actionCreateSaleOrder("draft");
}
Expand All @@ -30,24 +37,21 @@ odoo.define("point_of_sale.CreateOrderPopup", function (require) {
async _actionCreateSaleOrder(order_state) {
// Create Sale Order
await this._createSaleOrder(order_state);

// Delete current order
const current_order = this.env.pos.get_order();
this.env.pos.removeOrder(current_order);
this.env.pos.removeOrder(this.currentOrder);
this.env.pos.add_new_order();

// Close popup
return await super.confirm();
}

async _createSaleOrder(order_state) {
const current_order = this.env.pos.get_order();
framework.blockUI();
return await this.env.services
.rpc({
model: "sale.order",
method: "create_order_from_pos",
args: [current_order.export_as_JSON(), order_state],
args: [this.currentOrder.export_as_JSON(), order_state],
})
.catch(function (error) {
throw error;
Expand Down
35 changes: 35 additions & 0 deletions pos_order_to_sale_order/static/src/js/models.esm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/** @odoo-module **/

import {Order} from "point_of_sale.models";
import Registries from "point_of_sale.Registries";

const PosOrderToSaleOrderCommitmentDate = (OriginalOrder) =>
class extends OriginalOrder {
constructor() {
super(...arguments);
this.commitment_date = false;
}
get_commitment_date() {
return this.commitment_date;
}
set_commitment_date(commitment_date) {
if (!commitment_date) {
this.commitment_date = false;
} else {
this.commitment_date = new Date(commitment_date).toISOString();
}
}
export_as_JSON() {
const result = super.export_as_JSON(...arguments);
result.commitment_date = this.get_commitment_date();
return result;
}
init_from_JSON(json) {
super.init_from_JSON(...arguments);
this.set_commitment_date(json.commitment_date || false);
}
};

Registries.Model.extend(Order, PosOrderToSaleOrderCommitmentDate);

export default PosOrderToSaleOrderCommitmentDate;
32 changes: 20 additions & 12 deletions pos_order_to_sale_order/static/src/xml/CreateOrderPopup.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates id="template" xml:space="preserve">

<t t-name="CreateOrderPopup" owl="1">
<div class="popup popup-create-sale-order">

<header>
<div class="title">Create Order</div>
</header>

<main class="body">

<table>
<tbody>
<tr
t-if="env.pos.config.iface_sale_order_allow_commitment_date"
>
<td>
<div class="row">
<label
class="col-sm-2 col-form-label"
for="commitment_date"
>
Commitment Date
</label>
<input
class="input col-sm-10"
type="datetime-local"
t-on-change="updateCommitmentDate"
name="commitment_date"
/>
</div>
</td>
</tr>
<tr t-if="env.pos.config.iface_create_draft_sale_order">
<td>
<div
Expand All @@ -25,7 +41,6 @@
</div>
</td>
</tr>

<tr t-if="env.pos.config.iface_create_confirmed_sale_order">
<td>
<div
Expand All @@ -39,7 +54,6 @@
</div>
</td>
</tr>

<tr t-if="env.pos.config.iface_create_delivered_sale_order">
<td>
<div
Expand All @@ -54,7 +68,6 @@
</div>
</td>
</tr>

<tr t-if="env.pos.config.iface_create_invoiced_sale_order">
<td>
<div
Expand All @@ -69,18 +82,13 @@
<span>Create Invoiced Sale Order</span>
</div>
</td>

</tr>
</tbody>
</table>

</main>

<footer class="footer">
<div class="button" t-on-click="cancel">Discard</div>
</footer>

</div>
</t>

</templates>
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ ProductScreen.do.clickPartnerButton();
ProductScreen.do.clickCustomer("Addison Olson");

PosOrderToSaleOrder.do.clickCreateOrderButton();
PosOrderToSaleOrder.do.addCommitmentDate();
PosOrderToSaleOrder.do.clickCreateInvoicedOrderButton();

ProductScreen.check.isShown();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ class DoExt extends Do {
},
];
}
addCommitmentDate() {
return [
{
content: "Add Commitment Date",
trigger: ".popup-create-sale-order input[name='commitment_date']",
run: () => {
this.trigger("input", {
target: {value: "2024-01-01T16:00:00"},
});
},
},
];
}
}

const methods = createTourMethods("PosOrderToSaleOrder", DoExt);
Expand Down
7 changes: 7 additions & 0 deletions pos_order_to_sale_order/tests/test_module.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,10 @@
order.order_line[1].name,
"'Product Note' must not contains in sale order line description",
)
self.assertTrue(

Check warning on line 65 in pos_order_to_sale_order/tests/test_module.py

View check run for this annotation

Codecov / codecov/patch

pos_order_to_sale_order/tests/test_module.py#L65

Added line #L65 was not covered by tests
order.commitment_date,
)
self.assertEqual(

Check warning on line 68 in pos_order_to_sale_order/tests/test_module.py

View check run for this annotation

Codecov / codecov/patch

pos_order_to_sale_order/tests/test_module.py#L68

Added line #L68 was not covered by tests
order.commitment_date.strftime("%Y-%m-%d %H:%M:%S"),
"2024-01-01 16:00:00",
)
14 changes: 8 additions & 6 deletions pos_order_to_sale_order/views/view_res_config_settings.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="view_res_config_settings_form" model="ir.ui.view">
<field name="model">res.config.settings</field>
<field name="inherit_id" ref="point_of_sale.res_config_settings_view_form" />
<field name="arch" type="xml">

<xpath expr="//div[@id='pos_technical_section']" position="after">

<h2 name="create_sale_order">Sale Order Creation</h2>
<div class="row mt16 o_settings_container">
<div class="col-12 col-lg-6 o_setting_box">
Expand All @@ -18,7 +15,6 @@
<label for="pos_iface_create_draft_sale_order" />
</div>
</div>

<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="pos_iface_create_confirmed_sale_order" />
Expand All @@ -27,7 +23,6 @@
<label for="pos_iface_create_confirmed_sale_order" />
</div>
</div>

<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="pos_iface_create_delivered_sale_order" />
Expand All @@ -36,7 +31,6 @@
<label for="pos_iface_create_delivered_sale_order" />
</div>
</div>

<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="pos_iface_create_invoiced_sale_order" />
Expand All @@ -45,6 +39,14 @@
<label for="pos_iface_create_invoiced_sale_order" />
</div>
</div>
<div class="col-12 col-lg-6 o_setting_box">
<div class="o_setting_left_pane">
<field name="iface_sale_order_allow_commitment_date" />
</div>
<div class="o_setting_right_pane">
<label for="iface_sale_order_allow_commitment_date" />
</div>
</div>
</div>
</xpath>
</field>
Expand Down