Skip to content

Commit

Permalink
Fixed full refund (VOID, ex annullamento) and partially refund (ex. R…
Browse files Browse the repository at this point in the history
…eso Merce).

Added Fiscal Operator to User and Employee
  • Loading branch information
martin authored and Borruso committed Jan 23, 2024
1 parent 5d75e1c commit 8fc4f72
Show file tree
Hide file tree
Showing 14 changed files with 299 additions and 237 deletions.
4 changes: 3 additions & 1 deletion fiscal_epos_print/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
"website": "https://github.com/OCA/l10n-italy",
"maintainers": ["eLBati"],
"depends": [
"point_of_sale","hr","pos_hr",
"point_of_sale",
"hr",
"pos_hr",
# TODO is this necessary?
# 'pos_order_mgmt'
],
Expand Down
2 changes: 2 additions & 0 deletions fiscal_epos_print/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@
from . import pos_order
from . import pos_session
from . import res_config_settings
from . import res_users
from . import hr_employee_base
from . import hr_employee
24 changes: 7 additions & 17 deletions fiscal_epos_print/models/hr_employee.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
from odoo import api, fields, models

from odoo import _, api, fields, models
from odoo.exceptions import ValidationError

class HrEmployeeBase(models.AbstractModel):

_inherit = 'hr.employee.base'
class HrEmployeeInherit(models.AbstractModel):
_inherit = "hr.employee"

fiscal_operator_number = fields.Char("Fiscal Printer Operator",size=1, default="1",tracking=True)
fiscal_operator_number = fields.Char(
string="Fiscal Printer Operator", size=1, default="1", tracking=True
)

class HrEmployee(models.AbstractModel):
_inherit = 'hr.employee'

fiscal_operator_number = fields.Char("Fiscal Printer Operator",size=1, default="1",tracking=True)

@api.depends('fiscal_operator_number')
@api.onchange("fiscal_operator_number")
def _onchange_fiscal_operator_number(self):
for rec in self:
if rec.user_id:
rec.user_id.fiscal_operator_number = rec.fiscal_operator_number

class ResUsers(models.Model):
_inherit = 'res.users'

fiscal_operator_number = fields.Char("Fiscal Printer Operator",size=1, default="1")
10 changes: 10 additions & 0 deletions fiscal_epos_print/models/hr_employee_base.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import fields, models


class HrEmployeeBaseInherit(models.AbstractModel):
_name = "hr.employee.base"
_inherit = ["hr.employee.base", "mail.thread"]

fiscal_operator_number = fields.Char(
string="Fiscal Printer Operator", size=1, default="1", tracking=True
)
9 changes: 5 additions & 4 deletions fiscal_epos_print/models/pos_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class PosOrder(models.Model):
refund_report = fields.Integer(string="Closure reference")
refund_doc_num = fields.Integer(string="Document Number")
refund_cash_fiscal_serial = fields.Char(string="Refund Cash Serial")

refund_full_refund = fields.Boolean(string="Full Refund", default=False)
fiscal_receipt_number = fields.Integer(
string="Fiscal receipt number",
)
Expand All @@ -32,6 +32,7 @@ def _order_fields(self, ui_order):
res["refund_cash_fiscal_serial"] = ui_order.get(
"refund_cash_fiscal_serial", False
)
res["refund_full_refund"] = ui_order.get("refund_full_refund", False)
res["fiscal_receipt_number"] = ui_order.get("fiscal_receipt_number", False)
res["fiscal_receipt_amount"] = ui_order.get("fiscal_receipt_amount", False)
res["fiscal_receipt_date"] = ui_order.get("fiscal_receipt_date", False)
Expand Down Expand Up @@ -65,10 +66,9 @@ def update_fiscal_receipt_values(self, pos_order):
fiscal_printer_serial = (
pos_order.get("fiscal_printer_serial")
or self.config_id.fiscal_printer_serial
)

)
fiscal_operator_number = pos_order.get("fiscal_operator_number")

if po:
po.write(
{
Expand Down Expand Up @@ -101,6 +101,7 @@ def _export_for_ui(self, order):
"refund_report": order.refund_report,
"refund_doc_num": order.refund_doc_num,
"refund_cash_fiscal_serial": order.refund_cash_fiscal_serial,
"refund_full_refund": order.refund_full_refund,
"fiscal_receipt_number": order.fiscal_receipt_number,
"fiscal_receipt_amount": order.fiscal_receipt_amount,
"fiscal_receipt_date": order.fiscal_receipt_date,
Expand Down
20 changes: 3 additions & 17 deletions fiscal_epos_print/models/pos_session.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class PosSession(models.Model):
_inherit = 'pos.session'
_inherit = "pos.session"

def _loader_params_pos_payment_method(self):
result = super()._loader_params_pos_payment_method()
Expand All @@ -27,20 +27,6 @@ def _loader_params_hr_employee(self):
def _get_pos_ui_hr_employee(self, params):
employees = super()._get_pos_ui_hr_employee(params)
for employee in employees:
emp = self.env['hr.employee'].browse(employee['id'])
employee['fiscal_operator_number'] = emp.fiscal_operator_number
emp = self.env["hr.employee"].browse(employee["id"])
employee["fiscal_operator_number"] = emp.fiscal_operator_number
return employees
# employees = self.env['hr.employee'].search_read(**params['search_params'])
# employee_ids = [employee['id'] for employee in employees]
# user_ids = [employee['user_id'] for employee in employees if employee['user_id']]
# manager_ids = self.env['res.users'].browse(user_ids).filtered(lambda user: self.config_id.group_pos_manager_id in user.groups_id).mapped('id')

# employees_barcode_pin = self.env['hr.employee'].browse(employee_ids).get_barcodes_and_pin_hashed()
# bp_per_employee_id = {bp_e['id']: bp_e for bp_e in employees_barcode_pin}
# for employee in employees:
# employee['role'] = 'manager' if employee['user_id'] and employee['user_id'] in manager_ids else 'cashier'
# employee['barcode'] = bp_per_employee_id[employee['id']]['barcode']
# employee['pin'] = bp_per_employee_id[employee['id']]['pin']
# employee['fiscal_operator_number'] = bp_per_employee_id[employee['id']]['fiscal_operator_number']

# return employees
9 changes: 9 additions & 0 deletions fiscal_epos_print/models/res_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from odoo import fields, models


class ResUsersInherit(models.Model):
_inherit = "res.users"

fiscal_operator_number = fields.Char(
string="Fiscal Printer Operator", size=1, default="1"
)
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,9 @@ odoo.define("fiscal_epos_print.EpsonFP81IIComponent", function (require) {
body: _t("Please confirm to reprint the last receipt"),
});
if (confirmed) {
fp90.printFiscalReprintLast();
fp90.printFiscalReprintLast(
this.env.pos.cashier.fiscal_operator_number || "1"
);
} else {
// TODO not exist
// this.chrome.loading_hide();
Expand Down Expand Up @@ -163,8 +165,10 @@ odoo.define("fiscal_epos_print.EpsonFP81IIComponent", function (require) {
body: _t("Please confirm to execute the Printer Fiscal Closure"),
});
if (confirmed) {
// Fp90.printFiscalReport();
fp90.printFiscalXZReport();
// Fp90.printFiscalReport();
fp90.printFiscalXZReport(
this.env.pos.cashier.fiscal_operator_number || "1"
);
} else {
// TODO not exist
// this.chrome.loading_hide();
Expand All @@ -186,7 +190,9 @@ odoo.define("fiscal_epos_print.EpsonFP81IIComponent", function (require) {
),
});
if (confirmed) {
fp90.printFiscalXReport();
fp90.printFiscalXReport(
this.env.pos.cashier.fiscal_operator_number || "1"
);
} else {
// TODO not exist
// this.chrome.loading_hide();
Expand Down
9 changes: 7 additions & 2 deletions fiscal_epos_print/static/src/js/Popups/RefundInfoPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ odoo.define("fiscal_epos_print.RefundInfoPopup", function (require) {
this.inputRefundDate = useRef("inputRefundDate");
this.inputRefundDocNum = useRef("inputRefundDocNum");
this.inputRefundCashFiscalSerial = useRef("inputRefundCashFiscalSerial");
this.inputRefundFullRefund = useRef("inputRefundFullRefund");
this.inputDatePicker = this.initializeDatePicker();
}

Expand All @@ -24,9 +25,10 @@ odoo.define("fiscal_epos_print.RefundInfoPopup", function (require) {
function allValid() {
return self.$el
.find("input")
.not("#refund_full_refund")
.toArray()
.every(function (element) {
return element.value && element.value !== "";
return element.value && element.value != "";
});
}

Expand All @@ -39,18 +41,21 @@ odoo.define("fiscal_epos_print.RefundInfoPopup", function (require) {
var refund_cash_fiscal_serial = this.$el
.find("#refund_cash_fiscal_serial")
.val();
var refund_full_refund = this.$el.find("#refund_full_refund").val();
this.env.pos.context = {
refund_details: true,
refund_date: refund_date,
refund_report: refund_report,
refund_doc_num: refund_doc_num,
refund_cash_fiscal_serial: refund_cash_fiscal_serial,
refund_full_refund: refund_full_refund,
};
this.env.pos.set_refund_data(
refund_date,
refund_report,
refund_doc_num,
refund_cash_fiscal_serial
refund_cash_fiscal_serial,
refund_full_refund
);
if (
this.props.update_refund_info_button &&
Expand Down
Loading

0 comments on commit 8fc4f72

Please sign in to comment.