forked from tvtma/OpenUpgrade
-
Notifications
You must be signed in to change notification settings - Fork 25
[MIG][13.0]l10n_vn: map account_tag with account_tax_report_line #337
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
Open
lathuat1997
wants to merge
1
commit into
Viindoo:13.0
Choose a base branch
from
lathuat1997:v13_mig_l10n_vn
base: 13.0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,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, """ | ||
|
||
| 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) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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.