-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IMP] tg_archive: правки для прохода pre-commit проверок
- Loading branch information
Showing
8 changed files
with
216 additions
and
106 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
../../../../tg_archive |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import setuptools | ||
|
||
setuptools.setup( | ||
setup_requires=['setuptools-odoo'], | ||
odoo_addon=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,9 @@ | ||
# -*- coding: utf-8 -*- | ||
{ | ||
"name": """Archive Tools for Tribal Gathering""", | ||
"version": "14.0.0.1.0", | ||
"author": "IT-Projects LLC, Eugene Molotov", | ||
"support": "[email protected]", | ||
"website": "https://www.it-projects.info", | ||
"website": "https://github.com/it-projects-llc/tg-addons", | ||
"license": "LGPL-3", | ||
"depends": [ | ||
"account", | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,113 +1,175 @@ | ||
from collections import defaultdict | ||
import logging | ||
|
||
from collections import defaultdict | ||
|
||
_logger = logging.getLogger(__name__) | ||
|
||
|
||
def method1(env, old_cr, company_id): | ||
records = env['account.move'].search([ | ||
("move_type", "=", "in_receipt"), | ||
("company_id", "=", company_id), | ||
("ref", "in", [False, ""]), | ||
("partner_id", "!=", False), | ||
]) | ||
records = env["account.move"].search( | ||
[ | ||
("move_type", "=", "in_receipt"), | ||
("company_id", "=", company_id), | ||
("ref", "in", [False, ""]), | ||
("partner_id", "!=", False), | ||
] | ||
) | ||
|
||
_logger.info("Using method 1") | ||
for receipt in records: | ||
old_cr.execute( | ||
"select id, reference, google_folder_id from account_voucher where date = %s and partner_id = %s and round(amount, 2) = %s", | ||
[receipt.invoice_date, receipt.partner_id.id, round(receipt.amount_total, 2)] | ||
"select id, reference, google_folder_id from account_voucher where date = %s and partner_id = %s and round(amount, 2) = %s", # noqa: B950 | ||
[ | ||
receipt.invoice_date, | ||
receipt.partner_id.id, | ||
round(receipt.amount_total, 2), | ||
], | ||
) | ||
rows = old_cr.fetchall() | ||
if len(rows) == 1: | ||
row = rows[0] | ||
_logger.info("%s, %s copied using method 1" % (receipt.invoice_date, receipt,)) | ||
receipt.write({ | ||
"ref": row[1], | ||
"google_folder_id": row[2], | ||
}) | ||
_logger.info( | ||
"%s, %s copied using method 1" | ||
% ( | ||
receipt.invoice_date, | ||
receipt, | ||
) | ||
) | ||
receipt.write( | ||
{ | ||
"ref": row[1], | ||
"google_folder_id": row[2], | ||
} | ||
) | ||
env.cr.commit() | ||
else: | ||
_logger.info("%s, %s skipped method 1: rows count %s, %s" % (receipt.invoice_date, receipt, len(rows), receipt.partner_id.name)) | ||
_logger.info( | ||
"%s, %s skipped method 1: rows count %s, %s" | ||
% (receipt.invoice_date, receipt, len(rows), receipt.partner_id.name) | ||
) | ||
|
||
|
||
def method2(env, old_cr, company_id): | ||
records = env['account.move'].search([ | ||
("move_type", "=", "in_receipt"), | ||
("company_id", "=", company_id), | ||
("ref", "in", [False, ""]), | ||
("partner_id", "!=", False), | ||
]) | ||
records = env["account.move"].search( | ||
[ | ||
("move_type", "=", "in_receipt"), | ||
("company_id", "=", company_id), | ||
("ref", "in", [False, ""]), | ||
("partner_id", "!=", False), | ||
] | ||
) | ||
|
||
counters = defaultdict(int) | ||
|
||
_logger.info("Using method 2") | ||
for receipt in records: | ||
key = (receipt.invoice_date, receipt.partner_id.id, round(receipt.amount_total, 2)) | ||
key = ( | ||
receipt.invoice_date, | ||
receipt.partner_id.id, | ||
round(receipt.amount_total, 2), | ||
) | ||
old_cr.execute( | ||
"select id, reference, google_folder_id from account_voucher where date = %s and partner_id = %s and round(amount, 2) = %s ORDER BY id DESC OFFSET %s LIMIT 1", | ||
list(key) + [counters[key]] | ||
"select id, reference, google_folder_id from account_voucher where date = %s and partner_id = %s and round(amount, 2) = %s ORDER BY id DESC OFFSET %s LIMIT 1", # noqa: B950 | ||
list(key) + [counters[key]], | ||
) | ||
counters[key] += 1 | ||
rows = old_cr.fetchall() | ||
if len(rows) == 1: | ||
row = rows[0] | ||
_logger.info("%s, %s copied using method 2" % (receipt.invoice_date, receipt,)) | ||
receipt.write({ | ||
"ref": row[1], | ||
"google_folder_id": row[2], | ||
}) | ||
_logger.info( | ||
"%s, %s copied using method 2" | ||
% ( | ||
receipt.invoice_date, | ||
receipt, | ||
) | ||
) | ||
receipt.write( | ||
{ | ||
"ref": row[1], | ||
"google_folder_id": row[2], | ||
} | ||
) | ||
env.cr.commit() | ||
else: | ||
_logger.info("%s, %s skipped method 2: rows count %s" % (receipt.invoice_date, receipt, len(rows))) | ||
_logger.info( | ||
"%s, %s skipped method 2: rows count %s" | ||
% (receipt.invoice_date, receipt, len(rows)) | ||
) | ||
|
||
|
||
def method3(env, old_cr, company_id): | ||
records = env['account.move'].search([ | ||
("move_type", "=", "in_receipt"), | ||
("company_id", "=", company_id), | ||
("google_folder_id", "=", False), | ||
("ref", "not in", [False, ""]), | ||
]) | ||
records = env["account.move"].search( | ||
[ | ||
("move_type", "=", "in_receipt"), | ||
("company_id", "=", company_id), | ||
("google_folder_id", "=", False), | ||
("ref", "not in", [False, ""]), | ||
] | ||
) | ||
|
||
_logger.info("Using method 3") | ||
for receipt in records: | ||
old_cr.execute( | ||
"select id, google_folder_id from account_voucher where date = %s and partner_id = %s and reference = %s and google_folder_id IS NOT NULL", | ||
"select id, google_folder_id from account_voucher where date = %s and partner_id = %s and reference = %s and google_folder_id IS NOT NULL", # noqa: B950 | ||
[receipt.invoice_date, receipt.partner_id.id, receipt.ref], | ||
) | ||
rows = old_cr.fetchall() | ||
if len(rows) == 1: | ||
row = rows[0] | ||
_logger.info("%s, %s copied using method 3" % (receipt.invoice_date, receipt,)) | ||
receipt.write({ | ||
"google_folder_id": row[1], | ||
}) | ||
_logger.info( | ||
"%s, %s copied using method 3" | ||
% ( | ||
receipt.invoice_date, | ||
receipt, | ||
) | ||
) | ||
receipt.write( | ||
{ | ||
"google_folder_id": row[1], | ||
} | ||
) | ||
env.cr.commit() | ||
else: | ||
_logger.info("%s, %s skipped method 3: rows count %s" % (receipt.invoice_date, receipt, len(rows))) | ||
_logger.info( | ||
"%s, %s skipped method 3: rows count %s" | ||
% (receipt.invoice_date, receipt, len(rows)) | ||
) | ||
|
||
|
||
def method4(env, old_cr, company_id): | ||
records = env['account.move'].search([ | ||
("move_type", "=", "in_receipt"), | ||
("company_id", "=", company_id), | ||
("google_folder_id", "=", False), | ||
("ref", "in", [False, ""]), | ||
("name", "!=", "/"), | ||
]) | ||
records = env["account.move"].search( | ||
[ | ||
("move_type", "=", "in_receipt"), | ||
("company_id", "=", company_id), | ||
("google_folder_id", "=", False), | ||
("ref", "in", [False, ""]), | ||
("name", "!=", "/"), | ||
] | ||
) | ||
|
||
_logger.info("Using method 4") | ||
for receipt in records: | ||
old_cr.execute( | ||
"select id, google_folder_id from account_voucher where number = %s and google_folder_id IS NOT NULL", | ||
"select id, google_folder_id from account_voucher where number = %s and google_folder_id IS NOT NULL", # noqa: B950 | ||
[receipt.name], | ||
) | ||
rows = old_cr.fetchall() | ||
if len(rows) == 1: | ||
row = rows[0] | ||
_logger.info("%s, %s copied using method 4" % (receipt.invoice_date, receipt,)) | ||
receipt.write({ | ||
"google_folder_id": row[1], | ||
}) | ||
_logger.info( | ||
"%s, %s copied using method 4" | ||
% ( | ||
receipt.invoice_date, | ||
receipt, | ||
) | ||
) | ||
receipt.write( | ||
{ | ||
"google_folder_id": row[1], | ||
} | ||
) | ||
env.cr.commit() | ||
else: | ||
_logger.info("%s, %s skipped method 4: rows count %s" % (receipt.invoice_date, receipt, len(rows))) | ||
_logger.info( | ||
"%s, %s skipped method 4: rows count %s" | ||
% (receipt.invoice_date, receipt, len(rows)) | ||
) |
Oops, something went wrong.