-
-
Notifications
You must be signed in to change notification settings - Fork 306
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
[14.0] [FIX] l10n_it_delivery_note: carrier syncing #3815
Closed
Closed
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 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
11 changes: 11 additions & 0 deletions
11
l10n_it_delivery_note/migrations/14.0.2.6.0/post-migrate.py
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,11 @@ | ||
from openupgradelib import openupgrade | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
# Sync every picking's carrier to their delivery_note | ||
picking_ids = env["stock.picking"].search( | ||
[("delivery_note_id", "!=", False), ("carrier_id", "!=", False)] | ||
) | ||
for picking in picking_ids: | ||
picking.delivery_note_id.carrier_id = picking.carrier_id |
75 changes: 75 additions & 0 deletions
75
l10n_it_delivery_note/migrations/14.0.2.6.0/pre-migrate.py
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,75 @@ | ||
from collections import defaultdict | ||
|
||
from openupgradelib import openupgrade | ||
|
||
|
||
@openupgrade.migrate() | ||
def migrate(env, version): | ||
# Get every carrier that was a 'res.partner' and create a 'delivery.carrier' | ||
env.cr.execute( | ||
"""SELECT id, carrier_id | ||
FROM stock_delivery_note | ||
WHERE carrier_id IS NOT NULL""" | ||
) | ||
res = env.cr.dictfetchall() | ||
|
||
# Group by carrier_id to not create duplicates | ||
new_res = defaultdict(list) | ||
for i in res: | ||
new_res[i.get("carrier_id")].append(i.get("id")) | ||
|
||
for (carrier_id, delivery_note_ids) in new_res.items(): | ||
partner_carrier_id = env["res.partner"].browse(carrier_id) | ||
|
||
carrier_product = env["product.product"].create( | ||
{ | ||
"name": partner_carrier_id.name, | ||
"type": "service", | ||
"sale_ok": False, | ||
"purchase_ok": False, | ||
"list_price": 0.0, | ||
"invoice_policy": "order", | ||
} | ||
) | ||
|
||
delivery_carrier_id = env["delivery.carrier"].create( | ||
{ | ||
"name": partner_carrier_id.name, | ||
"company_id": partner_carrier_id.company_id.id, | ||
"country_ids": [(4, partner_carrier_id.country_id.id)] | ||
if partner_carrier_id.country_id | ||
else [], | ||
"state_ids": [(4, partner_carrier_id.state_id.id)] | ||
if partner_carrier_id.state_id | ||
else [], | ||
"zip_from": partner_carrier_id.zip, | ||
"zip_to": partner_carrier_id.zip, | ||
"product_id": carrier_product.id, | ||
} | ||
) | ||
|
||
# If it's only one add a duplicate to | ||
# delivery note ids otherwise it would | ||
# be casted to tuple as '(id,)' and that will raise an error | ||
if len(delivery_note_ids) == 1: | ||
delivery_note_ids.append(delivery_note_ids[0]) | ||
|
||
# Update carrier in 'stock.picking' | ||
openupgrade.logged_query( | ||
env.cr, | ||
"""UPDATE stock_picking | ||
SET carrier_id={} | ||
WHERE delivery_note_id IN {}""".format( | ||
delivery_carrier_id.id, tuple(delivery_note_ids) | ||
), | ||
) | ||
|
||
# Remove carrier from delivery notes | ||
openupgrade.logged_query( | ||
env.cr, | ||
"""UPDATE stock_delivery_note | ||
SET carrier_id=NULL | ||
WHERE id IN {}""".format( | ||
tuple(delivery_note_ids) | ||
), | ||
) |
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
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
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
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
Oops, something went wrong.
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.
unica osservazione tu fai sempre la create del
delivery.carrier
in questo caso avrai vari delivery carrier con la stesso nome perché non c'è un raggruppo per partner quindi anche se il partner sul secondo DdT è lo stesso crea di nuovo ildelivery.carrier
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.
Grazie per avermelo fatto notare, mi era totalmente sfuggito.
Ora funziona come dovrebbe, fammi sapere se l'implementazione ti piace :)