Skip to content
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] purchase_partner_incoterm: fix migration script #2457

Draft
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Draft
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
31 changes: 16 additions & 15 deletions purchase_partner_incoterm/migrations/14.0.3.0.0/post-migration.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@


def migrate(cr, version):
env = api.Environment(cr, SUPERUSER_ID, {})
return
# env = api.Environment(cr, SUPERUSER_ID, {})

children = env["res.partner"].search(
[["commercial_partner_id", "!=", False], ["purchase_incoterm_id", "!=", False]]
)
# children = env["res.partner"].search(
# [["commercial_partner_id", "!=", False], ["purchase_incoterm_id", "!=", False]]
# )

seen = env["res.partner"].browse(False)
# seen = env["res.partner"].browse(False)

for child in children:
if child.parent_id.purchase_incoterm_id:
continue
if child.parent_id in seen:
continue
seen |= child.parent_id
child.parent_id.purchase_incoterm_id = child.purchase_incoterm_id
child.parent_id.purchase_incoterm_address_id = (
child.purchase_incoterm_address_id
)
# for child in children:
# if child.parent_id.purchase_incoterm_id:
# continue
# if child.parent_id in seen:
# continue
# seen |= child.parent_id
# child.parent_id.purchase_incoterm_id = child.purchase_incoterm_id
# child.parent_id.purchase_incoterm_address_id = (
# child.purchase_incoterm_address_id
# )
10 changes: 6 additions & 4 deletions purchase_partner_incoterm/models/purchase_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@ class PurchaseOrder(models.Model):
@api.onchange("partner_id")
def onchange_partner_id(self):
res = super().onchange_partner_id()
self.incoterm_id = self.partner_id.commercial_partner_id.purchase_incoterm_id
self.incoterm_address_id = (
self.partner_id.commercial_partner_id.purchase_incoterm_address_id
)
# Since https://github.com/OCA/purchase-workflow/pull/1533,
# purchase_incoterm_id and purchase_incoterm_address_id should be synced
# from parent to child partners. No need to retrieve incoterm
# from the commercial entity
self.incoterm_id = self.partner_id.purchase_incoterm_id
self.incoterm_address_id = self.partner_id.purchase_incoterm_address_id
return res
13 changes: 7 additions & 6 deletions purchase_partner_incoterm/models/res_partner.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@ class ResPartner(models.Model):
string="Default Purchase Incoterm Address",
)

@api.model
def _commercial_fields(self):
return super()._commercial_fields() + [
"purchase_incoterm_address_id",
"purchase_incoterm_id",
]
# TODO this should be enabled throught a config parameter
# @api.model
# def _commercial_fields(self):
# return super()._commercial_fields() + [
# "purchase_incoterm_address_id",
# "purchase_incoterm_id",
# ]
Loading