Initial commit: OCA Technical packages (595 packages)

This commit is contained in:
Ernad Husremovic 2025-08-29 15:43:03 +02:00
commit 2cc02aac6e
24950 changed files with 2318079 additions and 0 deletions

View file

@ -0,0 +1,3 @@
from . import pos_payment_change_wizard
from . import pos_payment_change_wizard_new_line
from . import pos_payment_change_wizard_old_line

View file

@ -0,0 +1,110 @@
# Copyright (C) 2015-Today GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import _, api, fields, models
from odoo.exceptions import UserError
from odoo.tools import float_compare
class PosPaymentChangeWizard(models.TransientModel):
_name = "pos.payment.change.wizard"
_description = "PoS Payment Change Wizard"
# Column Section
order_id = fields.Many2one(comodel_name="pos.order", string="Order", readonly=True)
old_line_ids = fields.One2many(
comodel_name="pos.payment.change.wizard.old.line",
inverse_name="wizard_id",
string="Old Payment Lines",
readonly=True,
)
new_line_ids = fields.One2many(
comodel_name="pos.payment.change.wizard.new.line",
inverse_name="wizard_id",
string="New Payment Lines",
)
amount_total = fields.Float(string="Total", readonly=True)
# View Section
@api.model
def default_get(self, fields):
PosOrder = self.env["pos.order"]
res = super().default_get(fields)
order = PosOrder.browse(self._context.get("active_id"))
old_lines_vals = []
for payment in order.payment_ids:
old_lines_vals.append(
(
0,
0,
{
"old_payment_method_id": payment.payment_method_id.id,
"amount": payment.amount,
},
)
)
res.update(
{
"order_id": order.id,
"amount_total": order.amount_total,
"old_line_ids": old_lines_vals,
}
)
return res
# View section
def button_change_payment(self):
self.ensure_one()
order = self.order_id
# Check if the total is correct
total = sum(self.mapped("new_line_ids.amount"))
if (
float_compare(
total,
self.amount_total,
precision_rounding=self.order_id.currency_id.rounding,
)
!= 0
):
raise UserError(
_(
"Differences between the two values for the POS"
" Order '%(name)s':\n\n"
" * Total of all the new payments %(total)s;\n"
" * Total of the POS Order %(amount_total)s;\n\n"
"Please change the payments.",
name=order.name,
total=total,
amount_total=order.amount_total,
)
)
# Change payment
new_payments = [
{
"pos_order_id": order.id,
"payment_method_id": line.new_payment_method_id.id,
"amount": line.amount,
"payment_date": fields.Date.context_today(self),
}
for line in self.new_line_ids
]
orders = order.change_payment(new_payments)
if len(orders) == 1:
# if policy is 'update', only close the pop up
action = {"type": "ir.actions.act_window_close"}
else:
# otherwise (refund policy), displays the 3 orders
action = self.env["ir.actions.act_window"]._for_xml_id(
"point_of_sale.action_pos_pos_form"
)
action["domain"] = [("id", "in", orders.ids)]
return action

View file

@ -0,0 +1,56 @@
# Copyright (C) 2015 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class PosPaymentChangeWizardLine(models.TransientModel):
_name = "pos.payment.change.wizard.new.line"
_description = "PoS Payment Change Wizard New Line"
wizard_id = fields.Many2one(
comodel_name="pos.payment.change.wizard",
required=True,
ondelete="cascade",
)
new_payment_method_id = fields.Many2one(
comodel_name="pos.payment.method",
string="Payment Method",
required=True,
domain=lambda s: s._domain_new_payment_method_id(),
)
company_currency_id = fields.Many2one(
comodel_name="res.currency",
store=True,
related="new_payment_method_id.company_id.currency_id",
string="Company Currency",
readonly=True,
help="Utility field to express amount currency",
)
amount = fields.Monetary(
required=True,
default=0.0,
currency_field="company_currency_id",
)
@api.model
def _domain_new_payment_method_id(self):
PosOrder = self.env["pos.order"]
order = PosOrder.browse(self.env.context.get("active_id"))
return [("id", "in", order.mapped("session_id.payment_method_ids").ids)]
# View Section
@api.model
def default_get(self, fields):
res = super().default_get(fields)
if "new_line_ids" not in self._context:
return res
balance = self._context.get("amount_total", 0.0)
for line in self.wizard_id.old_line_ids:
balance -= line.get("amount")
res.update({"amount": balance})
return res

View file

@ -0,0 +1,39 @@
# Copyright (C) 2015 - Today: GRAP (http://www.grap.coop)
# @author: Sylvain LE GAL (https://twitter.com/legalsylvain)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
class PosPaymentChangeWizardOldLine(models.TransientModel):
_name = "pos.payment.change.wizard.old.line"
_description = "PoS Payment Change Wizard Old Line"
wizard_id = fields.Many2one(
comodel_name="pos.payment.change.wizard",
required=True,
ondelete="cascade",
)
old_payment_method_id = fields.Many2one(
comodel_name="pos.payment.method",
string="Payment Method",
required=True,
readonly=True,
)
company_currency_id = fields.Many2one(
comodel_name="res.currency",
store=True,
related="old_payment_method_id.company_id.currency_id",
string="Company Currency",
readonly=True,
help="Utility field to express amount currency",
)
amount = fields.Monetary(
required=True,
readonly=True,
default=0.0,
currency_field="company_currency_id",
)

View file

@ -0,0 +1,54 @@
<?xml version="1.0" encoding="utf-8" ?>
<!--
Copyright (C) 2015-Today GRAP (http://www.grap.coop)
@author: Sylvain LE GAL (https://twitter.com/legalsylvain)
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
-->
<odoo>
<record id="view_pos_payment_change_wizard_form" model="ir.ui.view">
<field name="model">pos.payment.change.wizard</field>
<field name="arch" type="xml">
<form>
<group col="4">
<field name="order_id" />
<field name="amount_total" invisible="1" />
<field name="old_line_ids" colspan="4">
<tree>
<field name="old_payment_method_id" widget="selection" />
<field name="amount" sum="Total" />
</tree>
</field>
<newline />
<field
name="new_line_ids"
colspan="4"
context="{'new_line_ids': new_line_ids, 'amount_total': amount_total}"
>
<tree editable="bottom">
<field name="new_payment_method_id" widget="selection" />
<field name="amount" sum="Total" />
</tree>
</field>
</group>
<footer>
<button
name="button_change_payment"
string="Change Payments"
type="object"
class="oe_highlight"
/>
<button string="Cancel" class="oe_link" special="cancel" />
</footer>
</form>
</field>
</record>
<record id="action_pos_payment_change_wizard" model="ir.actions.act_window">
<field name="name">Change Payments</field>
<field name="res_model">pos.payment.change.wizard</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
</odoo>