summaryrefslogtreecommitdiff
path: root/addons/point_of_sale/wizard/pos_payment.py
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/point_of_sale/wizard/pos_payment.py
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/point_of_sale/wizard/pos_payment.py')
-rw-r--r--addons/point_of_sale/wizard/pos_payment.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/addons/point_of_sale/wizard/pos_payment.py b/addons/point_of_sale/wizard/pos_payment.py
new file mode 100644
index 00000000..40f37419
--- /dev/null
+++ b/addons/point_of_sale/wizard/pos_payment.py
@@ -0,0 +1,74 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from odoo import api, fields, models, _
+from odoo.tools import float_is_zero
+
+
+class PosMakePayment(models.TransientModel):
+ _name = 'pos.make.payment'
+ _description = 'Point of Sale Make Payment Wizard'
+
+ def _default_config(self):
+ active_id = self.env.context.get('active_id')
+ if active_id:
+ return self.env['pos.order'].browse(active_id).session_id.config_id
+ return False
+
+ def _default_amount(self):
+ active_id = self.env.context.get('active_id')
+ if active_id:
+ order = self.env['pos.order'].browse(active_id)
+ return order.amount_total - order.amount_paid
+ return False
+
+ def _default_payment_method(self):
+ active_id = self.env.context.get('active_id')
+ if active_id:
+ order_id = self.env['pos.order'].browse(active_id)
+ return order_id.session_id.payment_method_ids.sorted(lambda pm: pm.is_cash_count, reverse=True)[:1]
+ return False
+
+ config_id = fields.Many2one('pos.config', string='Point of Sale Configuration', required=True, default=_default_config)
+ amount = fields.Float(digits=0, required=True, default=_default_amount)
+ payment_method_id = fields.Many2one('pos.payment.method', string='Payment Method', required=True, default=_default_payment_method)
+ payment_name = fields.Char(string='Payment Reference')
+ payment_date = fields.Datetime(string='Payment Date', required=True, default=lambda self: fields.Datetime.now())
+
+ def check(self):
+ """Check the order:
+ if the order is not paid: continue payment,
+ if the order is paid print ticket.
+ """
+ self.ensure_one()
+
+ order = self.env['pos.order'].browse(self.env.context.get('active_id', False))
+ currency = order.currency_id
+
+ init_data = self.read()[0]
+ if not float_is_zero(init_data['amount'], precision_rounding=currency.rounding):
+ order.add_payment({
+ 'pos_order_id': order.id,
+ 'amount': order._get_rounded_amount(init_data['amount']),
+ 'name': init_data['payment_name'],
+ 'payment_method_id': init_data['payment_method_id'][0],
+ })
+
+ if order._is_pos_order_paid():
+ order.action_pos_order_paid()
+ order._create_order_picking()
+ return {'type': 'ir.actions.act_window_close'}
+
+ return self.launch_payment()
+
+ def launch_payment(self):
+ return {
+ 'name': _('Payment'),
+ 'view_mode': 'form',
+ 'res_model': 'pos.make.payment',
+ 'view_id': False,
+ 'target': 'new',
+ 'views': False,
+ 'type': 'ir.actions.act_window',
+ 'context': self.env.context,
+ }