diff --git a/pos_order_copy/README.rst b/pos_order_copy/README.rst new file mode 100644 index 0000000000..57f35c1ab5 --- /dev/null +++ b/pos_order_copy/README.rst @@ -0,0 +1,79 @@ +============== +Pos Order Copy +============== + +.. + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! This file is generated by oca-gen-addon-readme !! + !! changes will be overwritten. !! + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + !! source digest: sha256:15afbcfbd7ff0b646b5bbb008dbfdb7eff8cb51b08b53172535d77f16b3ea7b3 + !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + +.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png + :target: https://odoo-community.org/page/development-status + :alt: Beta +.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png + :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html + :alt: License: AGPL-3 +.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpos-lightgray.png?logo=github + :target: https://github.com/OCA/pos/tree/17.0/pos_order_copy + :alt: OCA/pos +.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png + :target: https://translation.odoo-community.org/projects/pos-17-0/pos-17-0-pos_order_copy + :alt: Translate me on Weblate +.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png + :target: https://runboat.odoo-community.org/builds?repo=OCA/pos&target_branch=17.0 + :alt: Try me on Runboat + +|badge1| |badge2| |badge3| |badge4| |badge5| + +Copy orders on point of sale view. + +**Table of contents** + +.. contents:: + :local: + +Bug Tracker +=========== + +Bugs are tracked on `GitHub Issues `_. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +`feedback `_. + +Do not contact contributors directly about support or help with technical issues. + +Credits +======= + +Authors +------- + +* Dixmit +* INVITU + +Contributors +------------ + +- Dixmit + + - Enric Tobella + +Maintainers +----------- + +This module is maintained by the OCA. + +.. image:: https://odoo-community.org/logo.png + :alt: Odoo Community Association + :target: https://odoo-community.org + +OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use. + +This module is part of the `OCA/pos `_ project on GitHub. + +You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute. diff --git a/pos_order_copy/__init__.py b/pos_order_copy/__init__.py new file mode 100644 index 0000000000..0650744f6b --- /dev/null +++ b/pos_order_copy/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/pos_order_copy/__manifest__.py b/pos_order_copy/__manifest__.py new file mode 100644 index 0000000000..dbc0aa3f77 --- /dev/null +++ b/pos_order_copy/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright 2024 Dixmit,INVITU +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +{ + "name": "Pos Order Copy", + "summary": """ + Copy Orders from PoS Frontend""", + "version": "17.0.1.0.0", + "license": "AGPL-3", + "author": "Dixmit,INVITU,Odoo Community Association (OCA)", + "website": "https://github.com/OCA/pos", + "depends": ["point_of_sale"], + "assets": { + "point_of_sale._assets_pos": [ + "pos_order_copy/static/src/**/*.js", + "pos_order_copy/static/src/**/*.xml", + ], + }, + "data": [], + "demo": [], +} diff --git a/pos_order_copy/models/__init__.py b/pos_order_copy/models/__init__.py new file mode 100644 index 0000000000..b2f4b5e054 --- /dev/null +++ b/pos_order_copy/models/__init__.py @@ -0,0 +1,2 @@ +from . import pos_order +from . import pos_session diff --git a/pos_order_copy/models/pos_order.py b/pos_order_copy/models/pos_order.py new file mode 100644 index 0000000000..6044d37b39 --- /dev/null +++ b/pos_order_copy/models/pos_order.py @@ -0,0 +1,18 @@ +# Copyright 2024 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import fields, models + + +class PosOrder(models.Model): + _inherit = "pos.order" + + date_order = fields.Datetime(copy=False) + user_id = fields.Many2one(copy=False) + last_order_preparation_change = fields.Char(copy=False) + sequence_number = fields.Integer(copy=False) + session_id = fields.Many2one(copy=False) + shipping_date = fields.Date(copy=False) + is_tipped = fields.Boolean(copy=False) + tip_amount = fields.Float(copy=False) + ticket_code = fields.Char(copy=False) diff --git a/pos_order_copy/models/pos_session.py b/pos_order_copy/models/pos_session.py new file mode 100644 index 0000000000..f482ce8ab7 --- /dev/null +++ b/pos_order_copy/models/pos_session.py @@ -0,0 +1,22 @@ +# Copyright 2024 Dixmit +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). + +from odoo import models + + +class PosSession(models.Model): + _inherit = "pos.session" + + def _pos_data_process(self, loaded_data): + result = super()._pos_data_process(loaded_data) + loaded_data["pos_order_copy_fields"] = [ + field_name + for field_name, field in self.env["pos.order"]._fields.items() + if field.copy and field.store and not field.automatic and not field.compute + ] + loaded_data["pos_order_line_copy_fields"] = [ + field_name + for field_name, field in self.env["pos.order.line"]._fields.items() + if field.copy and field.store and not field.automatic and not field.compute + ] + return result diff --git a/pos_order_copy/pyproject.toml b/pos_order_copy/pyproject.toml new file mode 100644 index 0000000000..4231d0cccb --- /dev/null +++ b/pos_order_copy/pyproject.toml @@ -0,0 +1,3 @@ +[build-system] +requires = ["whool"] +build-backend = "whool.buildapi" diff --git a/pos_order_copy/readme/CONTRIBUTORS.md b/pos_order_copy/readme/CONTRIBUTORS.md new file mode 100644 index 0000000000..0082723f81 --- /dev/null +++ b/pos_order_copy/readme/CONTRIBUTORS.md @@ -0,0 +1,2 @@ + - Dixmit + - Enric Tobella diff --git a/pos_order_copy/readme/DESCRIPTION.md b/pos_order_copy/readme/DESCRIPTION.md new file mode 100644 index 0000000000..9d959d90f8 --- /dev/null +++ b/pos_order_copy/readme/DESCRIPTION.md @@ -0,0 +1 @@ +Copy orders on point of sale view. diff --git a/pos_order_copy/static/description/icon.png b/pos_order_copy/static/description/icon.png new file mode 100644 index 0000000000..3a0328b516 Binary files /dev/null and b/pos_order_copy/static/description/icon.png differ diff --git a/pos_order_copy/static/description/index.html b/pos_order_copy/static/description/index.html new file mode 100644 index 0000000000..29bceea8e8 --- /dev/null +++ b/pos_order_copy/static/description/index.html @@ -0,0 +1,424 @@ + + + + + +Pos Order Copy + + + +
+

Pos Order Copy

+ + +

Beta License: AGPL-3 OCA/pos Translate me on Weblate Try me on Runboat

+

Copy orders on point of sale view.

+

Table of contents

+ +
+

Bug Tracker

+

Bugs are tracked on GitHub Issues. +In case of trouble, please check there if your issue has already been reported. +If you spotted it first, help us to smash it by providing a detailed and welcomed +feedback.

+

Do not contact contributors directly about support or help with technical issues.

+
+
+

Credits

+
+

Authors

+
    +
  • Dixmit
  • +
  • INVITU
  • +
+
+
+

Contributors

+
    +
  • Dixmit
      +
    • Enric Tobella
    • +
    +
  • +
+
+
+

Maintainers

+

This module is maintained by the OCA.

+Odoo Community Association +

OCA, or the Odoo Community Association, is a nonprofit organization whose +mission is to support the collaborative development of Odoo features and +promote its widespread use.

+

This module is part of the OCA/pos project on GitHub.

+

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.

+
+
+
+ + diff --git a/pos_order_copy/static/src/app/product_screen/CopyOrderButton.esm.js b/pos_order_copy/static/src/app/product_screen/CopyOrderButton.esm.js new file mode 100644 index 0000000000..cc77672a8c --- /dev/null +++ b/pos_order_copy/static/src/app/product_screen/CopyOrderButton.esm.js @@ -0,0 +1,25 @@ +/** @odoo-module */ +/* + Copyright 2024 Dixmit + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +*/ +import {Component} from "@odoo/owl"; +import {ProductScreen} from "@point_of_sale/app/screens/product_screen/product_screen"; +import {usePos} from "@point_of_sale/app/store/pos_hook"; + +export class CopyOrderButton extends Component { + setup() { + this.pos = usePos(); + } + + onClick() { + var order = this.pos.get_order(); + this.pos.copy_on_new_order(order); + this.pos.showScreen("ProductScreen"); + } +} +CopyOrderButton.template = "pos_order_copy.CopyOrderButton"; + +ProductScreen.addControlButton({ + component: CopyOrderButton, +}); diff --git a/pos_order_copy/static/src/app/product_screen/CopyOrderButton.xml b/pos_order_copy/static/src/app/product_screen/CopyOrderButton.xml new file mode 100644 index 0000000000..7d2f5a6296 --- /dev/null +++ b/pos_order_copy/static/src/app/product_screen/CopyOrderButton.xml @@ -0,0 +1,14 @@ + + + +
+ + + Duplicate Order +
+
+
diff --git a/pos_order_copy/static/src/app/store/pos_store.esm.js b/pos_order_copy/static/src/app/store/pos_store.esm.js new file mode 100644 index 0000000000..02e81ad87f --- /dev/null +++ b/pos_order_copy/static/src/app/store/pos_store.esm.js @@ -0,0 +1,50 @@ +/** @odoo-module */ +/* + Copyright 2024 Dixmit + License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl). +*/ +import {PosStore} from "@point_of_sale/app/store/pos_store"; +import {_t} from "@web/core/l10n/translation"; +import {patch} from "@web/core/utils/patch"; +import {uuidv4} from "@point_of_sale/utils"; + +patch(PosStore.prototype, { + async copy_on_new_order(currentOrder) { + if (!currentOrder) { + return; + } + if (this.isOpenOrderShareable()) { + this.sendDraftToServer(); + } + var json = currentOrder.export_as_JSON(); + if (this.selectedOrder) { + this.selectedOrder.firstDraft = false; + this.selectedOrder.updateSavedQuantity(); + } + var newJson = { + lines: [], + statement_ids: [], + }; + for (var field of Object.values(this.pos_order_copy_fields)) { + if (field !== "lines" && json[field] !== undefined) { + newJson[field] = json[field]; + } + } + const newOrder = this.createReactiveOrder(newJson); + // We need to enforce some fields to be the standard ones + newOrder.date_order = luxon.DateTime.now(); + newOrder.sequence_number = this.pos_session.sequence_number++; + newOrder.access_token = uuidv4(); + newOrder.ticketCode = newOrder._generateTicketCode(); + newOrder.uid = newOrder.generate_unique_id(); + newOrder.name = _t("Order %s", newOrder.uid); + this.orders.add(newOrder); + this.selectedOrder = newOrder; + return newOrder; + }, + async _processData(loadedData) { + await super._processData(...arguments); + this.pos_order_copy_fields = loadedData.pos_order_copy_fields; + this.pos_order_line_copy_fields = loadedData.pos_order_line_copy_fields; + }, +}); diff --git a/pos_order_copy/static/src/app/ticket_screen/ticket_screen.esm.js b/pos_order_copy/static/src/app/ticket_screen/ticket_screen.esm.js new file mode 100644 index 0000000000..f55475c565 --- /dev/null +++ b/pos_order_copy/static/src/app/ticket_screen/ticket_screen.esm.js @@ -0,0 +1,14 @@ +/** @odoo-module */ +/* + Copyright 2024 Dixmit + License OPL-1.0 or later (https://www.odoo.com/documentation/15.0/es/legal/licenses.html#odoo-apps). +*/ +import {TicketScreen} from "@point_of_sale/app/screens/ticket_screen/ticket_screen"; +import {patch} from "@web/core/utils/patch"; + +patch(TicketScreen.prototype, { + _copyOrder(order) { + this.pos.copy_on_new_order(order); + this.pos.showScreen("ProductScreen"); + }, +}); diff --git a/pos_order_copy/static/src/app/ticket_screen/ticket_screen.xml b/pos_order_copy/static/src/app/ticket_screen/ticket_screen.xml new file mode 100644 index 0000000000..68b6f94c5e --- /dev/null +++ b/pos_order_copy/static/src/app/ticket_screen/ticket_screen.xml @@ -0,0 +1,26 @@ + + + + + + + + + + +