Skip to content

Commit

Permalink
[IMP] tg_archive: правки для прохода pre-commit проверок
Browse files Browse the repository at this point in the history
  • Loading branch information
em230418 committed Oct 21, 2024
1 parent ede3f77 commit 8c4449d
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 106 deletions.
1 change: 1 addition & 0 deletions setup/tg_archive/odoo/addons/tg_archive
6 changes: 6 additions & 0 deletions setup/tg_archive/setup.py
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,
)
3 changes: 1 addition & 2 deletions tg_archive/__manifest__.py
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",
Expand Down
10 changes: 7 additions & 3 deletions tg_archive/models.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
from odoo import api, models, fields
from odoo import api, fields, models


class GoogleAttachmentArchiveMixin(models.AbstractModel):
_name = "google.attachment.archive.mixin"
google_folder_id = fields.Char(readonly=True)
attachment_archive_url = fields.Char(compute="_compute_attachment_archive_url", store=False, default="")
attachment_archive_url = fields.Char(
compute="_compute_attachment_archive_url", store=False, default=""
)

@api.depends("google_folder_id")
def _compute_attachment_archive_url(self):
for record in self:
if not record.google_folder_id:
record.attachment_archive_url = ""
else:
record.attachment_archive_url = "https://drive.google.com/drive/folders/" + record.google_folder_id
record.attachment_archive_url = (
"https://drive.google.com/drive/folders/" + record.google_folder_id
)


class AccountMove(models.Model):
Expand Down
79 changes: 50 additions & 29 deletions tg_archive/tools/copy_history.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from collections import defaultdict
import logging

# 653843
Expand All @@ -7,64 +6,86 @@


def method1(env, old_cr):
records = env['account.move'].search([
("move_type", "in", ["in_receipt", "out_receipt"]),
("google_folder_id", "!=", False),
])
records = env["account.move"].search(
[
("move_type", "in", ["in_receipt", "out_receipt"]),
("google_folder_id", "!=", False),
]
)

_logger.info("Using method 1")
for record in records:
old_cr.execute(
"select id from account_voucher where google_folder_id = %s",
[record.google_folder_id]
[record.google_folder_id],
)
rows = old_cr.fetchall()
if len(rows) == 1:
old_res_id = rows[0][0]
env.cr.execute("UPDATE mail_message SET (res_id,model) = (%s,%s) WHERE (res_id, model) = (%s, 'account.voucher')", [record.id, record._name, old_res_id])
env.cr.execute(
"UPDATE mail_message SET (res_id,model) = (%s,%s) WHERE (res_id, model) = (%s, 'account.voucher')", # noqa: B950
[record.id, record._name, old_res_id],
)
env.cr.commit()
else:
_logger.info("%s, %s skipped method 1: rows count %s" % (record.invoice_date, record, len(rows)))
_logger.info(
"%s, %s skipped method 1: rows count %s"
% (record.invoice_date, record, len(rows))
)


def method2(env, old_cr):
records = env['account.move'].search([
("move_type", "in", ["in_receipt", "out_receipt"]),
("google_folder_id", "=", False),
("name", "!=", "/"),
])
records = env["account.move"].search(
[
("move_type", "in", ["in_receipt", "out_receipt"]),
("google_folder_id", "=", False),
("name", "!=", "/"),
]
)

_logger.info("Using method 2")
for record in records:
old_cr.execute(
"select id from account_voucher where name = %s",
[record.name]
)
old_cr.execute("select id from account_voucher where name = %s", [record.name])
rows = old_cr.fetchall()
if len(rows) == 1:
old_res_id = rows[0][0]
env.cr.execute("UPDATE mail_message SET (res_id,model) = (%s,%s) WHERE (res_id, model) = (%s, 'account.voucher')", [record.id, record._name, old_res_id])
env.cr.execute(
"UPDATE mail_message SET (res_id,model) = (%s,%s) WHERE (res_id, model) = (%s, 'account.voucher')", # noqa: B950
[record.id, record._name, old_res_id],
)
env.cr.commit()
else:
_logger.info("%s, %s skipped method 2: rows count %s" % (record.invoice_date, record, len(rows)))
_logger.info(
"%s, %s skipped method 2: rows count %s"
% (record.invoice_date, record, len(rows))
)


def method3(env, old_cr):
records = env['account.move'].search([
("move_type", "in", ["in_receipt", "out_receipt"]),
("google_folder_id", "=", False),
("name", "=", "/"),
("ref", "not in", [False, ""]),
])
records = env["account.move"].search(
[
("move_type", "in", ["in_receipt", "out_receipt"]),
("google_folder_id", "=", False),
("name", "=", "/"),
("ref", "not in", [False, ""]),
]
)

_logger.info("Using method 3")
for record in records:
old_cr.execute(
"select id from account_voucher where reference = %s",
[record.ref]
"select id from account_voucher where reference = %s", [record.ref]
)
rows = old_cr.fetchall()
if len(rows) == 1:
old_res_id = rows[0][0]
env.cr.execute("UPDATE mail_message SET (res_id,model) = (%s,%s) WHERE (res_id, model) = (%s, 'account.voucher')", [record.id, record._name, old_res_id])
env.cr.execute(
"UPDATE mail_message SET (res_id,model) = (%s,%s) WHERE (res_id, model) = (%s, 'account.voucher')", # noqa: B950
[record.id, record._name, old_res_id],
)
env.cr.commit()
else:
_logger.info("%s, %s skipped method 3: rows count %s" % (record.invoice_date, record, len(rows)))
_logger.info(
"%s, %s skipped method 3: rows count %s"
% (record.invoice_date, record, len(rows))
)
174 changes: 118 additions & 56 deletions tg_archive/tools/copy_missing_field_values.py
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))
)
Loading

0 comments on commit 8c4449d

Please sign in to comment.