odoo-addon-hr-payroll-document 16.0.1.3.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. odoo/addons/hr_payroll_document/README.rst +95 -0
  2. odoo/addons/hr_payroll_document/__init__.py +2 -0
  3. odoo/addons/hr_payroll_document/__manifest__.py +24 -0
  4. odoo/addons/hr_payroll_document/data/email_payroll_employee.xml +20 -0
  5. odoo/addons/hr_payroll_document/i18n/ca_ES.po +309 -0
  6. odoo/addons/hr_payroll_document/i18n/es.po +309 -0
  7. odoo/addons/hr_payroll_document/i18n/hr_payroll_document.pot +245 -0
  8. odoo/addons/hr_payroll_document/i18n/it.po +315 -0
  9. odoo/addons/hr_payroll_document/models/__init__.py +4 -0
  10. odoo/addons/hr_payroll_document/models/hr_employee.py +34 -0
  11. odoo/addons/hr_payroll_document/models/ir_attachment.py +14 -0
  12. odoo/addons/hr_payroll_document/models/ir_attachment_payroll_custom.py +18 -0
  13. odoo/addons/hr_payroll_document/models/res_users.py +18 -0
  14. odoo/addons/hr_payroll_document/readme/CONTRIBUTORS.rst +5 -0
  15. odoo/addons/hr_payroll_document/readme/DESCRIPTION.rst +4 -0
  16. odoo/addons/hr_payroll_document/security/ir.model.access.csv +3 -0
  17. odoo/addons/hr_payroll_document/static/description/icon.png +0 -0
  18. odoo/addons/hr_payroll_document/static/description/index.html +438 -0
  19. odoo/addons/hr_payroll_document/tests/__init__.py +1 -0
  20. odoo/addons/hr_payroll_document/tests/common.py +76 -0
  21. odoo/addons/hr_payroll_document/tests/test.docx +0 -0
  22. odoo/addons/hr_payroll_document/tests/test.pdf +0 -0
  23. odoo/addons/hr_payroll_document/tests/test_hr_payroll_document.py +122 -0
  24. odoo/addons/hr_payroll_document/views/hr_employee_views.xml +20 -0
  25. odoo/addons/hr_payroll_document/views/res_users_views.xml +27 -0
  26. odoo/addons/hr_payroll_document/wizard/__init__.py +1 -0
  27. odoo/addons/hr_payroll_document/wizard/payroll_management_wizard.py +216 -0
  28. odoo/addons/hr_payroll_document/wizard/payroll_management_wizard.xml +42 -0
  29. odoo_addon_hr_payroll_document-16.0.1.3.1.dist-info/METADATA +112 -0
  30. odoo_addon_hr_payroll_document-16.0.1.3.1.dist-info/RECORD +32 -0
  31. odoo_addon_hr_payroll_document-16.0.1.3.1.dist-info/WHEEL +5 -0
  32. odoo_addon_hr_payroll_document-16.0.1.3.1.dist-info/top_level.txt +1 -0
@@ -0,0 +1,216 @@
1
+ import base64
2
+ from base64 import b64decode
3
+
4
+ from pypdf import PdfReader, PdfWriter, errors
5
+
6
+ from odoo import _, fields, models
7
+ from odoo.exceptions import UserError, ValidationError
8
+
9
+
10
+ class PayrollManagamentWizard(models.TransientModel):
11
+ _name = "payroll.management.wizard"
12
+ _description = "Payroll Management"
13
+
14
+ subject = fields.Char(
15
+ help="Enter the title of the payroll whether it is the month, week, day, etc."
16
+ )
17
+ payrolls = fields.Many2many(
18
+ "ir.attachment",
19
+ "payrol_rel",
20
+ "doc_id",
21
+ "attach_id3",
22
+ copy=False,
23
+ )
24
+
25
+ def _get_fallback_reader(self, pdf_reader):
26
+ # Override to use another reader
27
+ pass
28
+
29
+ def _read_page_content(self, pdf_reader, page, fallback_reader=None):
30
+ try:
31
+ page_content = page.extract_text().split()
32
+ except errors.PdfReadError:
33
+ if fallback_reader:
34
+ # The original page cannot be read:
35
+ # read the simplified page in the fallback_reader
36
+ page_number = pdf_reader.get_page_number(page)
37
+ fallback_page = fallback_reader.get_page(page_number)
38
+ page_content = fallback_page.extract_text().split()
39
+ else:
40
+ raise
41
+ return page_content
42
+
43
+ def _extract_employees(self, pdf_reader, fallback_reader=None):
44
+ employee_to_pages = dict()
45
+ not_found_ids = set()
46
+
47
+ # Find all IDs of the employees
48
+ for page in pdf_reader.pages:
49
+ page_content = self._read_page_content(
50
+ pdf_reader, page, fallback_reader=fallback_reader
51
+ )
52
+ for value in page_content:
53
+ if self.validate_id(value) and value != self.env.company.vat:
54
+ employee = self.env["hr.employee"].search(
55
+ [("identification_id", "=", value)]
56
+ )
57
+ if employee:
58
+ employee_to_pages.setdefault(employee, []).append(page)
59
+ else:
60
+ not_found_ids.add(value)
61
+ break
62
+
63
+ return employee_to_pages, not_found_ids
64
+
65
+ def _build_employee_payroll(self, file_name, pdf_pages, encryption_key=None):
66
+ """Return the path to the created payroll.
67
+
68
+ Optionally encrypt the payroll file with `encryption_key`.
69
+ """
70
+ pdfWriter = PdfWriter()
71
+ for page in pdf_pages:
72
+ pdfWriter.add_page(page)
73
+
74
+ path = "/tmp/" + file_name
75
+
76
+ if encryption_key:
77
+ pdfWriter.encrypt(encryption_key, algorithm="AES-256")
78
+
79
+ with open(path, "wb") as f:
80
+ pdfWriter.write(f)
81
+ return path
82
+
83
+ def _show_employees_action(self):
84
+ return {
85
+ "name": _("Payrolls sent"),
86
+ "type": "ir.actions.act_window",
87
+ "res_model": "hr.employee",
88
+ "views": [
89
+ (False, "kanban"),
90
+ (False, "tree"),
91
+ (False, "form"),
92
+ (False, "activity"),
93
+ ],
94
+ }
95
+
96
+ def send_payrolls(self):
97
+ self.merge_pdfs()
98
+ # Validate if company have country
99
+ if not self.env.company.country_id:
100
+ raise UserError(_("You must to filled country field of company"))
101
+
102
+ reader = PdfReader("/tmp/merged-pdf.pdf")
103
+
104
+ try:
105
+ employee_to_pages, not_found = self._extract_employees(reader)
106
+ except errors.PdfReadError:
107
+ # Couldn't read the file, try again with another reader
108
+ fallback_reader = self._get_fallback_reader(reader)
109
+ if fallback_reader:
110
+ employee_to_pages, not_found = self._extract_employees(
111
+ reader, fallback_reader=fallback_reader
112
+ )
113
+ else:
114
+ raise
115
+
116
+ for employee, pages in employee_to_pages.items():
117
+ encryption_key = (
118
+ None if employee.no_payroll_encryption else employee.identification_id
119
+ )
120
+ path = self._build_employee_payroll(
121
+ _(
122
+ "Payroll %(subject)s %(employee)s.pdf",
123
+ employee=employee.name,
124
+ subject=self.subject,
125
+ ),
126
+ pages,
127
+ encryption_key=encryption_key,
128
+ )
129
+ # Send payroll to the employee
130
+ self.send_mail(employee, path)
131
+
132
+ next_action = self._show_employees_action()
133
+ if not_found:
134
+ return {
135
+ "type": "ir.actions.client",
136
+ "tag": "display_notification",
137
+ "params": {
138
+ "title": _("Employees not found"),
139
+ "message": _("IDs whose employee has not been found: ")
140
+ + ", ".join(list(not_found)),
141
+ "sticky": True,
142
+ "type": "warning",
143
+ "next": next_action,
144
+ },
145
+ }
146
+
147
+ return {
148
+ "type": "ir.actions.client",
149
+ "tag": "display_notification",
150
+ "params": {
151
+ "title": _("Payrolls sent"),
152
+ "message": _("Payrolls sent to employees correctly"),
153
+ "sticky": False,
154
+ "type": "success",
155
+ "next": next_action,
156
+ },
157
+ }
158
+
159
+ def merge_pdfs(self):
160
+ # Merge the pdfs together
161
+ pdfs = []
162
+ for file in self.payrolls:
163
+ b64 = file.datas
164
+ btes = b64decode(b64, validate=True)
165
+ if btes[0:4] != b"%PDF":
166
+ raise ValidationError(_("Missing pdf file signature"))
167
+ f = open("/tmp/" + file.name, "wb")
168
+ f.write(btes)
169
+ f.close()
170
+ pdfs.append(f.name)
171
+
172
+ merger = PdfWriter()
173
+
174
+ for pdf in pdfs:
175
+ merger.append(pdf)
176
+
177
+ merger.write("/tmp/merged-pdf.pdf")
178
+ merger.close()
179
+
180
+ def send_mail(self, employee, path):
181
+ # Open Payrolls of employee and encode content
182
+ with open(path, "rb") as pdf_file:
183
+ encoded_string = base64.b64encode(pdf_file.read())
184
+
185
+ # Attach file to email
186
+ ir_values = {
187
+ "name": _("Payroll") + "_" + self.subject + "_" + employee.name,
188
+ "type": "binary",
189
+ "datas": encoded_string,
190
+ "store_fname": encoded_string,
191
+ "res_model": "hr.employee",
192
+ "res_id": employee.id,
193
+ }
194
+
195
+ # Save payroll attachment to all employee payrolls attachments
196
+ self.env["ir.attachment.payroll.custom"].create(
197
+ {
198
+ "attachment_id": self.env["ir.attachment"].create(ir_values).id,
199
+ "employee": employee.name,
200
+ "subject": self.subject,
201
+ "identification_id": employee.identification_id,
202
+ }
203
+ )
204
+
205
+ # Send mail
206
+ mail_template = self.env.ref(
207
+ "hr_payroll_document.payroll_employee_email_template"
208
+ )
209
+ data_id = [(6, 0, [self.env["ir.attachment"].create(ir_values).id])]
210
+ mail_template.attachment_ids = data_id
211
+ mail_template.with_context(**{"subject": self.subject}).send_mail(
212
+ employee.id, force_send=True
213
+ )
214
+
215
+ def validate_id(self, code):
216
+ return self.env["hr.employee"]._validate_payroll_identification(code=code)
@@ -0,0 +1,42 @@
1
+ <?xml version="1.0" encoding="utf-8" ?>
2
+ <odoo>
3
+ <record id="payrolls_management_wizard_form" model="ir.ui.view">
4
+ <field name="name">payroll.management.wizard.form</field>
5
+ <field name="model">payroll.management.wizard</field>
6
+ <field name="arch" type="xml">
7
+ <form>
8
+ <sheet>
9
+ <group>
10
+ <field name="subject" required="1" />
11
+ </group>
12
+ <field name="payrolls" widget="many2many_binary" />
13
+ <footer>
14
+ <button
15
+ string="Send"
16
+ name="send_payrolls"
17
+ type="object"
18
+ class="oe_highlight"
19
+ />
20
+ <button
21
+ string="Close"
22
+ class="btn btn-secondary"
23
+ special="cancel"
24
+ />
25
+ </footer>
26
+ </sheet>
27
+ </form>
28
+ </field>
29
+ </record>
30
+ <record id="payrolls_management_wizard_action" model="ir.actions.act_window">
31
+ <field name="name">Payrolls Management</field>
32
+ <field name="res_model">payroll.management.wizard</field>
33
+ <field name="view_mode">form</field>
34
+ <field name="target">new</field>
35
+ </record>
36
+
37
+ <menuitem
38
+ id="payrolls_management_wizard_menu_action"
39
+ action="payrolls_management_wizard_action"
40
+ parent="hr.menu_hr_root"
41
+ />
42
+ </odoo>
@@ -0,0 +1,112 @@
1
+ Metadata-Version: 2.1
2
+ Name: odoo-addon-hr_payroll_document
3
+ Version: 16.0.1.3.1
4
+ Summary: Manage payroll for each employee
5
+ Home-page: https://github.com/OCA/payroll
6
+ Author: APSL, Odoo Community Association (OCA)
7
+ Author-email: support@odoo-community.org
8
+ License: AGPL-3
9
+ Classifier: Programming Language :: Python
10
+ Classifier: Framework :: Odoo
11
+ Classifier: Framework :: Odoo :: 16.0
12
+ Classifier: License :: OSI Approved :: GNU Affero General Public License v3
13
+ Classifier: Development Status :: 5 - Production/Stable
14
+ Requires-Python: >=3.10
15
+ Requires-Dist: odoo<16.1dev,>=16.0a
16
+ Requires-Dist: pypdf
17
+
18
+ .. image:: https://odoo-community.org/readme-banner-image
19
+ :target: https://odoo-community.org/get-involved?utm_source=readme
20
+ :alt: Odoo Community Association
21
+
22
+ =====================
23
+ HR - Payroll Document
24
+ =====================
25
+
26
+ ..
27
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
28
+ !! This file is generated by oca-gen-addon-readme !!
29
+ !! changes will be overwritten. !!
30
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
31
+ !! source digest: sha256:0a1433fb1fb696e8ffb0fb469e9d901e496d1363488ef86b830516e681153057
32
+ !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
33
+
34
+ .. |badge1| image:: https://img.shields.io/badge/maturity-Production%2FStable-green.png
35
+ :target: https://odoo-community.org/page/development-status
36
+ :alt: Production/Stable
37
+ .. |badge2| image:: https://img.shields.io/badge/license-AGPL--3-blue.png
38
+ :target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
39
+ :alt: License: AGPL-3
40
+ .. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fpayroll-lightgray.png?logo=github
41
+ :target: https://github.com/OCA/payroll/tree/16.0/hr_payroll_document
42
+ :alt: OCA/payroll
43
+ .. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
44
+ :target: https://translation.odoo-community.org/projects/payroll-16-0/payroll-16-0-hr_payroll_document
45
+ :alt: Translate me on Weblate
46
+ .. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
47
+ :target: https://runboat.odoo-community.org/builds?repo=OCA/payroll&target_branch=16.0
48
+ :alt: Try me on Runboat
49
+
50
+ |badge1| |badge2| |badge3| |badge4| |badge5|
51
+
52
+ This module have a wizard view to manage the different payrolls of employees which is identified by the identification_id attribute.
53
+
54
+ By default, the employee's payroll is encrypted using their identification number.
55
+ This behavior can be changed by the employee in their profile or by HR in the employee's form.
56
+
57
+ **Table of contents**
58
+
59
+ .. contents::
60
+ :local:
61
+
62
+ Bug Tracker
63
+ ===========
64
+
65
+ Bugs are tracked on `GitHub Issues <https://github.com/OCA/payroll/issues>`_.
66
+ In case of trouble, please check there if your issue has already been reported.
67
+ If you spotted it first, help us to smash it by providing a detailed and welcomed
68
+ `feedback <https://github.com/OCA/payroll/issues/new?body=module:%20hr_payroll_document%0Aversion:%2016.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
69
+
70
+ Do not contact contributors directly about support or help with technical issues.
71
+
72
+ Credits
73
+ =======
74
+
75
+ Authors
76
+ ~~~~~~~
77
+
78
+ * APSL
79
+
80
+ Contributors
81
+ ~~~~~~~~~~~~
82
+
83
+ * Antoni Marroig Campomar <amarroig@apsl.net>
84
+ * Miquel Alzanillas Monserrat <malzanillas@apsl.net>
85
+ * `PyTech <https://www.pytech.it>`_:
86
+
87
+ * Simone Rubino <simone.rubino@pytech.it>
88
+
89
+ Maintainers
90
+ ~~~~~~~~~~~
91
+
92
+ This module is maintained by the OCA.
93
+
94
+ .. image:: https://odoo-community.org/logo.png
95
+ :alt: Odoo Community Association
96
+ :target: https://odoo-community.org
97
+
98
+ OCA, or the Odoo Community Association, is a nonprofit organization whose
99
+ mission is to support the collaborative development of Odoo features and
100
+ promote its widespread use.
101
+
102
+ .. |maintainer-peluko00| image:: https://github.com/peluko00.png?size=40px
103
+ :target: https://github.com/peluko00
104
+ :alt: peluko00
105
+
106
+ Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
107
+
108
+ |maintainer-peluko00|
109
+
110
+ This module is part of the `OCA/payroll <https://github.com/OCA/payroll/tree/16.0/hr_payroll_document>`_ project on GitHub.
111
+
112
+ You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
@@ -0,0 +1,32 @@
1
+ odoo/addons/hr_payroll_document/README.rst,sha256=gnEiBQD7eQvxSwdIHZQ8nXht_D6i6RfezRaymCUI-Yk,3610
2
+ odoo/addons/hr_payroll_document/__init__.py,sha256=4xA2wEP-VC0HAopaFS8ihQ1VjQDTg34AvIvOmq-alrM,42
3
+ odoo/addons/hr_payroll_document/__manifest__.py,sha256=zKq6D4bbJUroMYMsBLMQ7qs1Ni2k1jK3kCeA4LAJcJw,712
4
+ odoo/addons/hr_payroll_document/data/email_payroll_employee.xml,sha256=bcbPEqEcHJAQ5gQxWyW_RGkx6XCC8ZHL3lKvSrxHRt8,2584
5
+ odoo/addons/hr_payroll_document/i18n/ca_ES.po,sha256=x9rc2KF29yK5nFKVn4ffYANE2pRc50KOTvj4vM3BzR4,13297
6
+ odoo/addons/hr_payroll_document/i18n/es.po,sha256=HIK_JaWp3MMNIcHj9nO1yNHXKLDY6cGrb6Ip4B-h99w,13339
7
+ odoo/addons/hr_payroll_document/i18n/hr_payroll_document.pot,sha256=5w_QGw5Y7RtWga2EO0rmn-JWD3L3oHdcH85feJOFdho,10535
8
+ odoo/addons/hr_payroll_document/i18n/it.po,sha256=FQbSoHhE3VB2hXWksrCH33Nd32DmiNyQ1-PwHs0MoEA,13780
9
+ odoo/addons/hr_payroll_document/models/__init__.py,sha256=3ScZSP21GsBH37D9M28TsVaCfGoAJbzR527Q_XT1Tmk,121
10
+ odoo/addons/hr_payroll_document/models/hr_employee.py,sha256=JH6PJvD72smXandgN12aMMQSoWfscEH_ATjbq64UsVo,1399
11
+ odoo/addons/hr_payroll_document/models/ir_attachment.py,sha256=yAWi0rX88nOxa4sePk2iEMtm2hUrolapquA5EAdUd3I,295
12
+ odoo/addons/hr_payroll_document/models/ir_attachment_payroll_custom.py,sha256=Hnqiz3LgzDlnDkjA1u4-gscFuy09m6Jl41WTHUiQUEE,535
13
+ odoo/addons/hr_payroll_document/models/res_users.py,sha256=Ol7-Q1oFY5Y4b9iCPaE_SVvhi_V5qUSoZdKWAP4o11g,469
14
+ odoo/addons/hr_payroll_document/readme/CONTRIBUTORS.rst,sha256=TxfEr7Mh4BDGoHADSh4cSWe0ucHlTbJpuAsGbu6oJj8,181
15
+ odoo/addons/hr_payroll_document/readme/DESCRIPTION.rst,sha256=c_IeQyc--lKq_aYC19ieTHK5MXArSE8IxalPX2ZPTEs,312
16
+ odoo/addons/hr_payroll_document/security/ir.model.access.csv,sha256=W64tysGGKd4g_riQcuKJK0j5um9vgyd-xD9WzX5J4WE,310
17
+ odoo/addons/hr_payroll_document/static/description/icon.png,sha256=6xBPJauaFOF0KDHfHgQopSc28kKvxMaeoQFQWZtfZDo,9455
18
+ odoo/addons/hr_payroll_document/static/description/index.html,sha256=d-RUJG3G_xfHi1zSnSOCKo-bffPQBgrbvGKHzk1uSt0,13254
19
+ odoo/addons/hr_payroll_document/tests/__init__.py,sha256=qllw2tYyKSOtLtmPAudIhnJTNvqIVcW0P4y39LtWMxE,39
20
+ odoo/addons/hr_payroll_document/tests/common.py,sha256=yP_fgauwszSiJcu0s5XvQBJpxbCS_s89HyDFWIgJfl4,2634
21
+ odoo/addons/hr_payroll_document/tests/test.docx,sha256=Ba_5DoZ5yWG_WvxZlW9kvRU_XgyzK3pbs_OEYyE7P4Q,18655
22
+ odoo/addons/hr_payroll_document/tests/test.pdf,sha256=5I3tdxTT9SpLeyREtjxJErUhrU7VGBhKDN78T-j0r7A,33335
23
+ odoo/addons/hr_payroll_document/tests/test_hr_payroll_document.py,sha256=ozjFQqEEodo0M6AdW4N1fHArOjW-pkWoA2_0pNxd6ac,4172
24
+ odoo/addons/hr_payroll_document/views/hr_employee_views.xml,sha256=pR_hbtLkCXZ7v1gtHsnuDhCrkOyhuoSwtMeb6Kkp5SU,761
25
+ odoo/addons/hr_payroll_document/views/res_users_views.xml,sha256=VFjqhxngsf7YTbd_7-uvHFPxKVfk1Vf_9aqvV01TKIY,1019
26
+ odoo/addons/hr_payroll_document/wizard/__init__.py,sha256=IkYY2iCn8l-ZaOF5QeQ9HDJl5bzzxCpsfeFvSCcl8x4,40
27
+ odoo/addons/hr_payroll_document/wizard/payroll_management_wizard.py,sha256=lpJLfzvNge2Pm-by-ifX7C3ojjxcNfaNwcOfNosdBSg,7329
28
+ odoo/addons/hr_payroll_document/wizard/payroll_management_wizard.xml,sha256=7K-cZsZ7tMB-LSobFzI4y9vCB4xVz5m4b0v6XqpZO38,1647
29
+ odoo_addon_hr_payroll_document-16.0.1.3.1.dist-info/METADATA,sha256=Z8NYvC_Pnqz66s_IDql4UsvpObHcraZHh1lmBJ_SrdA,4202
30
+ odoo_addon_hr_payroll_document-16.0.1.3.1.dist-info/WHEEL,sha256=tZoeGjtWxWRfdplE7E3d45VPlLNQnvbKiYnx7gwAy8A,92
31
+ odoo_addon_hr_payroll_document-16.0.1.3.1.dist-info/top_level.txt,sha256=qBj40grFkGOfDZ2WDSw3y1RnDlgG0u8rP8pvGNdbz4w,5
32
+ odoo_addon_hr_payroll_document-16.0.1.3.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.45.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+