Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions addons/account/migrations/13.0.1.1/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -1044,9 +1044,9 @@ def migrate(env, version):
fill_res_partner_ranks(env)
try_to_fill_account_account_tag_country_id(env)
create_account_tax_repartition_lines(env)
move_tags_from_taxes_to_repartition_lines(env)
# move_tags_from_taxes_to_repartition_lines(env)
assign_tax_repartition_line_to_move_lines(env)
assign_account_tags_to_move_lines(env)
# assign_account_tags_to_move_lines(env)
Comment on lines +1047 to +1049
Copy link
Author

Choose a reason for hiding this comment

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

2 dòng này có tác dụng map các thẻ tài khoản mà đang gắn trực tiếp với thuế sang các dòng trên thuế, sau đó map các thẻ với các phát sinh kế toán tương ứng.
Cách map này hiện tại không phù hợp với nghiệp vụ và các thẻ tài khoản đang có trên dữ liệu của khách hiện tại nên em comment lại đoạn này.
Người dùng có thể tự tạo ra các thẻ mới và gắn theo ý muốn, chưa rõ trong trường hợp đó thì cách map hiện tại của OCA có hợp lý không nên em chưa xóa 2 hàm này.

compute_balance_for_draft_invoice_lines(env)
_recompute_move_entries_totals(env)
openupgrade.load_data(
Expand Down
97 changes: 97 additions & 0 deletions addons/l10n_vn/migrations/13.0.2.0/post-migration.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
from openupgradelib import openupgrade


def assign_account_tags_to_repartition_lines(env):
company_ids = env['res.company'].search([]).ids
map_data = []
for company_id in company_ids:
map_xml_id_data = [
('tax_purchase_vat10','l10n_vn.account_tax_report_line_03_02_01_vn','l10n_vn.account_tax_report_line_03_01_01_vn'),
('tax_purchase_vat5','l10n_vn.account_tax_report_line_02_02_01_vn','l10n_vn.account_tax_report_line_02_01_01_vn'),
('tax_purchase_vat0','l10n_vn.account_tax_report_line_01_02_01_vn'),
('tax_sale_vat10','l10n_vn.account_tax_report_line_03_02_02_vn','l10n_vn.account_tax_report_line_03_01_02_vn'),
('tax_sale_vat5','l10n_vn.account_tax_report_line_02_02_02_vn','l10n_vn.account_tax_report_line_02_01_02_vn'),
('tax_sale_vat0','l10n_vn.account_tax_report_line_01_02_02_vn'),
]
for data in map_xml_id_data:
tax = env.ref('l10n_vn.' + str(company_id) + '_' + data[0])
invoice_repartition_lines = tax.invoice_repartition_line_ids
refund_repartition_lines = tax.refund_repartition_line_ids
base_report_line_data = env.ref(data[1])
tax_report_line_data = len(data) > 2 and env.ref(data[2]) or False

for line in invoice_repartition_lines.filtered_domain([('repartition_type', '=', 'base')]):
map_data.extend([(line.id, tag.id) for tag in base_report_line_data.tag_ids.filtered_domain([('tax_negate', '=', False)])])
for line in refund_repartition_lines.filtered_domain([('repartition_type', '=', 'base')]):
map_data.extend([(line.id, tag.id) for tag in base_report_line_data.tag_ids.filtered_domain([('tax_negate', '=', True)])])

if tax_report_line_data:
for line in invoice_repartition_lines.filtered_domain([('repartition_type', '=', 'tax')]):
map_data.extend([(line.id, tag.id) for tag in tax_report_line_data.tag_ids.filtered_domain([('tax_negate', '=', False)])])
for line in refund_repartition_lines.filtered_domain([('repartition_type', '=', 'tax')]):
map_data.extend([(line.id, tag.id) for tag in tax_report_line_data.tag_ids.filtered_domain([('tax_negate', '=', True)])])

sql_query = ""
sub_query = """
INSERT INTO account_account_tag_account_tax_repartition_line_rel (
account_tax_repartition_line_id,account_account_tag_id)
VALUES %s;
"""
for data in map_data:
sql_query += sub_query

openupgrade.logged_query(
env.cr, sql_query, tuple(data for data in map_data)
)


def assign_account_tags_to_move_lines(env):
# move lines with tax repartition lines
openupgrade.logged_query(
env.cr, """
Comment on lines +48 to +51
Copy link
Author

Choose a reason for hiding this comment

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

Hàm này lấy từ file post-migration của module account, có tác dụng gắn các thẻ từ các dòng trên Thuế vào các phát sinh kế toán tương ứng.

INSERT INTO account_account_tag_account_move_line_rel (
account_move_line_id, account_account_tag_id)
SELECT aml.id, aat_atr_rel.account_account_tag_id
FROM account_move_line aml
JOIN account_tax_repartition_line atrl ON aml.tax_repartition_line_id = atrl.id
JOIN account_account_tag_account_tax_repartition_line_rel aat_atr_rel ON
aat_atr_rel.account_tax_repartition_line_id = atrl.id
ON CONFLICT DO NOTHING"""
)
# move lines with taxes
openupgrade.logged_query(
env.cr, """
INSERT INTO account_account_tag_account_move_line_rel (
account_move_line_id, account_account_tag_id)
SELECT aml.id, aat_atr_rel.account_account_tag_id
FROM account_move_line aml
JOIN account_move am ON aml.move_id = am.id
JOIN account_move_line_account_tax_rel amlatr ON amlatr.account_move_line_id = aml.id
JOIN account_tax_repartition_line atrl ON (
atrl.invoice_tax_id = amlatr.account_tax_id AND atrl.repartition_type = 'base')
JOIN account_account_tag_account_tax_repartition_line_rel aat_atr_rel ON
aat_atr_rel.account_tax_repartition_line_id = atrl.id
WHERE aml.old_invoice_line_id IS NOT NULL AND am.type in ('out_invoice', 'in_invoice')
ON CONFLICT DO NOTHING"""
)
openupgrade.logged_query(
env.cr, """
INSERT INTO account_account_tag_account_move_line_rel (
account_move_line_id, account_account_tag_id)
SELECT aml.id, aat_atr_rel.account_account_tag_id
FROM account_move_line aml
JOIN account_move am ON aml.move_id = am.id
JOIN account_move_line_account_tax_rel amlatr ON amlatr.account_move_line_id = aml.id
JOIN account_tax_repartition_line atrl ON (
atrl.refund_tax_id = amlatr.account_tax_id AND atrl.repartition_type = 'base')
JOIN account_account_tag_account_tax_repartition_line_rel aat_atr_rel ON
aat_atr_rel.account_tax_repartition_line_id = atrl.id
WHERE aml.old_invoice_line_id IS NOT NULL AND am.type in ('out_refund', 'in_refund')
ON CONFLICT DO NOTHING"""
)


@openupgrade.migrate()
def migrate(env, version):
assign_account_tags_to_repartition_lines(env)
assign_account_tags_to_move_lines(env)