Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MIG] [18.0] import_export_templating: migrated module #657

Open
wants to merge 5 commits into
base: 18.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions import_export_templating/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

{
"name": "Import / Export Templating",
"version": "17.0.1.0.0",
"version": "18.0.1.0.0",
"license": "LGPL-3",
"author": "Serpent Consulting Services Pvt. Ltd.",
"maintainer": "Serpent Consulting Services Pvt. Ltd.",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

summary should not be blank.
also company website link should be https

Expand All @@ -14,7 +14,10 @@
import-export for non-technical users of ERP.
""",
"depends": ["web"],
"data": ["security/ir.model.access.csv", "wizard/wiz_download_template_view.xml"],
"data": [
"security/ir.model.access.csv",
"wizard/wiz_download_template_view.xml"
],
# Odoo App Store Specific
"images": ["static/description/Banner_import_export_templating_17.png"],
"installable": True,
Expand Down
Binary file modified import_export_templating/static/description/header-logo.png
100644 → 100755
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 8 additions & 8 deletions import_export_templating/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ <h3 style="letter-spacing:2px;font-weight:900;color:#000;text-transform:uppercas
<h3 class="mt16"
style="font-weight: bold;font-family:'Montserrat', sans-serif">
<a style="color:#000;"
href="https://apps.odoo.com/apps/modules/17.0/odoo_office365_calendar/"
href="https://apps.odoo.com/apps/modules/14.0/odoo_office365_calendar/"
target="_blank"
style="font-family:'Montserrat', sans-serif;">
<img class="img m-auto shadow"
Expand Down Expand Up @@ -278,7 +278,7 @@ <h3 style="letter-spacing:2px;font-weight:900;color:#000;text-transform:uppercas
<h3 class="mt16"
style="font-weight: bold; font-family:'Montserrat', sans-serif">
<a style="color:#000;"
href="https://apps.odoo.com/apps/modules/17.0/hr_attendances_overtime/"
href="https://apps.odoo.com/apps/modules/16.0/hr_attendances_overtime/"
target="_blank"
style="font-family:'Montserrat', sans-serif;">
<img class="img m-auto shadow"
Expand Down Expand Up @@ -323,7 +323,7 @@ <h3 style="letter-spacing:2px;font-weight:900;color:#000;text-transform:uppercas
<h3 class="mt16"
style="font-weight: bold; font-family:'Montserrat', sans-serif">
<a style="color:#000;"
href="https://apps.odoo.com/apps/modules/17.0/popup_reminder/"
href="https://apps.odoo.com/apps/modules/16.0/popup_reminder/"
target="_blank"
style="font-family:'Montserrat', sans-serif;">
<img class="img m-auto shadow"
Expand All @@ -342,7 +342,7 @@ <h3 style="letter-spacing:2px;font-weight:900;color:#000;text-transform:uppercas
<h3 class="mt16"
style="font-weight: bold; font-family:'Montserrat', sans-serif">
<a style="color:#000;"
href="https://apps.odoo.com/apps/modules/17.0/sale_dost/"
href="https://apps.odoo.com/apps/modules/14.0/sale_dost/"
target="_blank"
style="font-family:'Montserrat', sans-serif;">
<img class="img m-auto shadow"
Expand Down Expand Up @@ -470,7 +470,7 @@ <h3 style="letter-spacing:2px;font-weight:900;color:#000;text-transform:uppercas
<div class="row">
<div class="col mb16">
<div class="text-center pt16 pb16">
<a href="https://apps.odoo.com/apps/modules/16.0/eduerp_base/" target="_blank"
<a href="https://apps.odoo.com/apps/modules/15.0/school/" target="_blank"
style="font-family:'Montserrat', sans-serif;">
<img src="images/education.png" alt="Education" width="100" height="100"/>
<h3 class="mt16"
Expand All @@ -482,7 +482,7 @@ <h3 style="letter-spacing:2px;font-weight:900;color:#000;text-transform:uppercas
</div>
<div class="col mb16">
<div class="text-center pt16 pb16">
<a href="https://apps.odoo.com/apps/modules/17.0/property_ee/"
<a href="https://apps.odoo.com/apps/modules/16.0/property/"
target="_blank" style="font-family:'Montserrat', sans-serif;">
<img src="images/property.png" alt="Property" width="100" height="100"/>
<h3 class="mt16"
Expand Down Expand Up @@ -518,7 +518,7 @@ <h3 style="letter-spacing:2px;font-weight:900;color:#000;text-transform:uppercas
</div>
<div class="col mb16">
<div class="text-center pt16 pb16">
<a href="https://apps.odoo.com/apps/modules/17.0/servisa/" target="_blank"
<a href="https://apps.odoo.com/apps/modules/15.0/servisa/" target="_blank"
style="font-family:'Montserrat', sans-serif;">
<img src="images/visa.png" alt="Visa" width="100" height="100"/>
<h3 class="mt16"
Expand Down Expand Up @@ -592,7 +592,7 @@ <h3 style="letter-spacing:2px;font-weight:900;color:#000;text-transform:uppercas
</div>
<div class="col mb16">
<div class="text-center pt16 pb16">
<a href="https://apps.odoo.com/apps/modules/16.0/hotel/" target="_blank"
<a href="https://apps.odoo.com/apps/modules/15.0/hotel/" target="_blank"
style="font-family:'Montserrat', sans-serif;">
<img src="images/hotel.png" alt="Hotel" width="100" height="100"/>
<h3 class="mt16"
Expand Down
138 changes: 138 additions & 0 deletions import_export_templating/wizard/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,141 @@
# See LICENSE file for full copyright and licensing details.

from . import wiz_download_template

def download_template(self, row_values=None, error_reason=None, error_value=None):
"""This method is used for export template."""
fl = BytesIO()
workbook = xlwt.Workbook()
worksheet = workbook.add_sheet(self.ir_model.name)

# Define Styles
bold = xlwt.easyxf("font: bold 1;")
main_header = xlwt.easyxf(
"font: bold 1, height 270;"
" align: horiz center,vert center ,wrap 1;"
"borders :top hair, bottom hair,left hair, right hair, "
"bottom_color black,top_color black"
)
label_header = xlwt.easyxf(
"font: bold 1, height 230;"
" align: horiz center,vert center ,wrap 1;"
"borders :top hair, bottom hair,left hair, right hair, "
"bottom_color black,top_color black"
)

self._setup_worksheet_layout(worksheet, main_header, bold)

if not self.fields_list_ids and not error_value:
raise UserError(_("Fields should not be blank!"))

if self.fields_list_ids:
self._populate_field_data(worksheet, label_header)
elif row_values and error_value:
self._populate_error_data(worksheet, row_values, error_reason, error_value, label_header)

workbook.save(fl)
fl.seek(0)
buf = base64.encodebytes(fl.read())
ctx = dict(self._context)
vals = {"file": buf}
ctx.update(vals)
self.env.args = self._cr, self._uid, misc.frozendict(ctx)
file_id = self.env["wiz.template.file"].create(
{"file": buf, "name": self.ir_model.model + ".xls"}
)
print("\n\n\n self.ir_model.model", self.ir_model.model)

return {
"res_id": file_id.id,
"type": "ir.actions.act_window",
"view_type": "form",
"view_mode": "form",
"res_model": "wiz.template.file",
"context": ctx,
"target": "new",
}

def _setup_worksheet_layout(self, worksheet, main_header, bold):
"""Configure the initial layout of the worksheet."""
worksheet.row(0).height = 500
for i, width in enumerate([6200, 9500, 9500, 9500, 9500]):
worksheet.col(i).width = width

worksheet.write_merge(0, 0, 0, 4, "Data Import Template", main_header)
for row in range(1, 3):
worksheet.write_merge(row, row, 0, 4, "")
worksheet.write_merge(3, 3, 0, 2, "Notes:", bold)
notes = [
"Please do not change the template headings.",
"First data column must be blank.",
'If you are uploading new records, "Naming Series" becomes mandatory, if present.',
"Only mandatory fields are necessary for new records. You can keep non-mandatory columns blank if you wish.",
"For updating, you can update only selective columns.",
"You can only upload upto 5000 records in one go. (may be less in some cases)",
]
for idx, note in enumerate(notes, start=4):
worksheet.write_merge(idx, idx, 0, 2, note)

data_import_notes = [
'Many2one: You can enter "NAME" of the relational model!',
'Many2many: You can enter "Name" of the relational model, separate by ";"',
"One2many: Let this blank! & Download Blank Template for displayed comodel to Import!",
"There should only be one required field in relational model for creation of new record.",
]
worksheet.write_merge(3, 3, 3, 4, "Data Import Notes:", bold)
for idx, note in enumerate(data_import_notes, start=5):
worksheet.write_merge(idx, idx, 3, 4, note)

headers = ["DocType:", "DocType", "Type:", "Mandatory:", "Column Labels:", "Start entering data this line"]

default_style = xlwt.easyxf("font: height 200;")

for row, header in enumerate(headers, start=12):
style_to_use = bold if row != 16 else default_style
worksheet.write(row, 0, header, style_to_use)

def _populate_field_data(self, worksheet, label_header):
"""Populate field-related data in the worksheet."""
for col_index, line in enumerate(self.fields_list_ids, start=1):
worksheet.col(col_index + 1).width = 9900
worksheet.write(13, col_index, line.name)
field_info = f"{line.ttype} Relation: {line.relation}"
worksheet.write(14, col_index, field_info)

is_delegated = (
(line.ttype == "many2one" and line.relation in [x.model for x in
self.ir_model.inherited_model_ids] and not line.related)
or line.ttype == "one2many"
)
is_required = "Yes" if line.required and not is_delegated else "No"
worksheet.write(15, col_index, is_required)
worksheet.write(16, col_index, line.field_description, label_header)

def _populate_error_data(self, worksheet, row_values, error_reason, error_value, label_header):
"""Populate error-related data in the worksheet."""
column_headers = ["Column Name:", "Type:", "Mandatory:", "Column Labels:"]
row_indices = [13, 14, 15, 16]

for row_idx, line in enumerate(row_values):
if row_idx in (0, 1, 2, 3):
header = column_headers[row_idx]
if header in line:
i = line.index(header)
del line[i]
for col, data in enumerate(line, start=1):
worksheet.col(col).width = 9900
worksheet.write(row_indices[row_idx], col, data, label_header if row_idx == 3 else None)

if row_idx == 4:
worksheet.write(16, len(line), "REASONS: (NOT CREATED RECORD)", label_header)

row_start = 17
for each_error in error_value:
del each_error[0]
reason = set(each_error) & set(error_reason)
for col, value in enumerate(each_error, start=1):
worksheet.col(col).width = 9900
worksheet.write(row_start, col, str(value))
worksheet.write(row_start, len(each_error) + 1,
f"{str(reason)}: Value not found in Database! Please create it first. Once created, remove (REASON) column for IMPORT!")
row_start += 1
Loading