Skip to content

Commit d4cfdf0

Browse files
committed
Merge PR #1056 into 17.0
Signed-off-by pedrobaeza
2 parents 47b3296 + 4569fb1 commit d4cfdf0

26 files changed

+1245
-193
lines changed

base_import_pdf_by_template/models/base_import_pdf_template.py

+11-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright 2024 Tecnativa - Víctor Martínez
22
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
import json
34
import re
45
from datetime import datetime
56

@@ -238,12 +239,18 @@ class BaseImportPdfTemplateLine(models.Model):
238239
selection=[
239240
("*Y-*d-*m", _("YY-dd-MM")),
240241
("*m-*d-*Y", _("MM-dd-YY")),
242+
("*d-*m-*Y", _("dd-MM-YY")),
241243
("*Y/*d/*m", _("YY/dd/MM")),
242244
("*m/*d/*Y", _("MM/dd/YY")),
243245
("*d.*m.*Y", _("dd.MM.YY")),
246+
("*d.*m.*y-short", _("dd.MM.yy")),
244247
("*d/*m/*Y", _("dd/MM/YY")),
245248
("*d/*m/*y-short", _("dd/MM/yy")),
246-
("*B *d, *Y", _("B d, YY")),
249+
("*B *d, *Y", _("B dd, YY")),
250+
("*b-short *d, *Y", _("b dd, YY")),
251+
("*d *b-short *Y", _("dd b YY")),
252+
("*d *B *Y", _("dd B YY")),
253+
("*d-*b-*y", _("dd-b-yy")),
247254
],
248255
)
249256
time_format = fields.Selection(
@@ -338,6 +345,7 @@ def _get_fixed_field_name_ttype_mapped(self):
338345
"integer": "fixed_value_integer",
339346
"selection": "fixed_value_selection",
340347
"text": "fixed_value_text",
348+
"json": "fixed_value_text",
341349
"many2one": "fixed_value",
342350
}
343351

@@ -347,6 +355,8 @@ def _get_fixed_value(self):
347355
f_value = self[f_name]
348356
if self.field_ttype == "selection":
349357
f_value = f_value.value
358+
elif self.field_ttype == "json":
359+
f_value = json.loads(f_value)
350360
return f_value
351361

352362
def _replace_text(self, text, letters, prefix):

base_import_pdf_by_template/security/security.xml

+12
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,16 @@
1414
name="domain_force"
1515
>[('template_id.company_id', 'in', [False] + company_ids)]</field>
1616
</record>
17+
<record id="rule_base_import_pdf_template_see_all" model="ir.rule">
18+
<field name="name">All Base Import Pdf Templates</field>
19+
<field name="model_id" ref="model_base_import_pdf_template" />
20+
<field name="domain_force">[(1, '=', 1)]</field>
21+
<field name="groups" eval="[(4, ref('base.group_no_one'))]" />
22+
</record>
23+
<record id="rule_base_import_pdf_template_line_see_all" model="ir.rule">
24+
<field name="name">All Base Import Pdf Template Lines</field>
25+
<field name="model_id" ref="model_base_import_pdf_template_line" />
26+
<field name="domain_force">[(1, '=', 1)]</field>
27+
<field name="groups" eval="[(4, ref('base.group_no_one'))]" />
28+
</record>
1729
</odoo>

base_import_pdf_by_template/views/base_import_pdf_template_line_views.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@
101101
<field
102102
name="fixed_value_text"
103103
string="Fixed value"
104-
invisible="value_type != 'fixed' or field_ttype != 'text'"
104+
invisible="value_type != 'fixed' or field_ttype not in ('text', 'json')"
105105
/>
106106
<field
107107
name="fixed_value"

base_import_pdf_by_template/wizards/wizard_base_import_pdf_upload.py

+20-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class WizardBaseImportPdfUpload(models.TransientModel):
1616
_description = "Wizard Base Import Pdf Upload"
1717

1818
model = fields.Char()
19+
record_ref = fields.Reference(selection="_selection_reference_value")
1920
attachment_ids = fields.Many2many(comodel_name="ir.attachment", string="Files")
2021
allowed_template_ids = fields.Many2many(
2122
comodel_name="base.import.pdf.template", compute="_compute_allowed_template_ids"
@@ -26,6 +27,15 @@ class WizardBaseImportPdfUpload(models.TransientModel):
2627
inverse_name="parent_id",
2728
)
2829

30+
@api.model
31+
def _selection_reference_value(self):
32+
models = (
33+
self.env["ir.model"]
34+
.sudo()
35+
.search([("transient", "=", False)], order="name asc")
36+
)
37+
return [(model.model, model.name) for model in models]
38+
2939
@api.depends("model")
3040
def _compute_allowed_template_ids(self):
3141
template_model = self.env["base.import.pdf.template"]
@@ -179,6 +189,7 @@ def _process_form(self):
179189
text = self.data
180190
template = self.template_id
181191
model = self.env[template.model]
192+
model = self.parent_id.record_ref or self.env[template.model]
182193
ctx = template._prepare_ctx_from_model(template.model)
183194
model_form = Form(model.with_context(**ctx))
184195
# Set the values of the header in Form
@@ -216,9 +227,16 @@ def _process_form(self):
216227
for key in ctx:
217228
if key.startswith("default_"):
218229
field = key.replace("default_", "")
219-
if field in vals:
230+
if field in vals and not self.parent_id.record_ref:
231+
vals.update({field: ctx[key]})
232+
elif self.parent_id.record_ref:
220233
vals.update({field: ctx[key]})
221-
record = model.with_context(**ctx).create(vals)
234+
# Create or update
235+
if self.parent_id.record_ref:
236+
model.with_context(**ctx).write(vals)
237+
record = self.parent_id.record_ref
238+
else:
239+
record = model.with_context(**ctx).create(vals)
222240
except AssertionError as err:
223241
raise UserError(err) from err
224242
if self.log_text:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
===================================
2+
Base Import Pdf by Template Account
3+
===================================
4+
5+
..
6+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
7+
!! This file is generated by oca-gen-addon-readme !!
8+
!! changes will be overwritten. !!
9+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
10+
!! source digest: sha256:6b053ca4747568743800079faebd557c69331b093cf1a6bc25fa9886d022dd66
11+
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
12+
13+
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
14+
:target: https://odoo-community.org/page/development-status
15+
:alt: Beta
16+
.. |badge2| image:: https://img.shields.io/badge/licence-AGPL--3-blue.png
17+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
18+
:alt: License: AGPL-3
19+
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fedi-lightgray.png?logo=github
20+
:target: https://github.com/OCA/edi/tree/17.0/base_import_pdf_by_template_account
21+
:alt: OCA/edi
22+
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
23+
:target: https://translation.odoo-community.org/projects/edi-17-0/edi-17-0-base_import_pdf_by_template_account
24+
:alt: Translate me on Weblate
25+
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
26+
:target: https://runboat.odoo-community.org/builds?repo=OCA/edi&target_branch=17.0
27+
:alt: Try me on Runboat
28+
29+
|badge1| |badge2| |badge3| |badge4| |badge5|
30+
31+
Added support for account to process the PDF attached to the invoice
32+
when creating the invoice from an email alias. Add 'Invoicing >
33+
Configuration > Management > Invoice Templates' menu item to Manager
34+
Accounting users.
35+
36+
**Table of contents**
37+
38+
.. contents::
39+
:local:
40+
41+
Bug Tracker
42+
===========
43+
44+
Bugs are tracked on `GitHub Issues <https://github.com/OCA/edi/issues>`_.
45+
In case of trouble, please check there if your issue has already been reported.
46+
If you spotted it first, help us to smash it by providing a detailed and welcomed
47+
`feedback <https://github.com/OCA/edi/issues/new?body=module:%20base_import_pdf_by_template_account%0Aversion:%2017.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
48+
49+
Do not contact contributors directly about support or help with technical issues.
50+
51+
Credits
52+
=======
53+
54+
Authors
55+
-------
56+
57+
* Tecnativa
58+
59+
Contributors
60+
------------
61+
62+
- `Tecnativa <https://www.tecnativa.com>`__:
63+
64+
- Víctor Martínez
65+
- Pedro M. Baeza
66+
67+
Maintainers
68+
-----------
69+
70+
This module is maintained by the OCA.
71+
72+
.. image:: https://odoo-community.org/logo.png
73+
:alt: Odoo Community Association
74+
:target: https://odoo-community.org
75+
76+
OCA, or the Odoo Community Association, is a nonprofit organization whose
77+
mission is to support the collaborative development of Odoo features and
78+
promote its widespread use.
79+
80+
.. |maintainer-victoralmau| image:: https://github.com/victoralmau.png?size=40px
81+
:target: https://github.com/victoralmau
82+
:alt: victoralmau
83+
84+
Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:
85+
86+
|maintainer-victoralmau|
87+
88+
This module is part of the `OCA/edi <https://github.com/OCA/edi/tree/17.0/base_import_pdf_by_template_account>`_ project on GitHub.
89+
90+
You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2024 Tecnativa - Víctor Martínez
2+
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
3+
{
4+
"name": "Base Import Pdf by Template Account",
5+
"version": "17.0.1.0.0",
6+
"website": "https://github.com/OCA/edi",
7+
"author": "Tecnativa, Odoo Community Association (OCA)",
8+
"license": "AGPL-3",
9+
"depends": ["account", "base_import_pdf_by_template"],
10+
"installable": True,
11+
"demo": [
12+
"demo/base_import_pdf_template.xml",
13+
],
14+
"data": [
15+
"security/ir.model.access.csv",
16+
"security/security.xml",
17+
"views/base_import_pdf_template_views.xml",
18+
],
19+
"maintainers": ["victoralmau"],
20+
}

0 commit comments

Comments
 (0)