-
-
Notifications
You must be signed in to change notification settings - Fork 733
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
11.0 Migration partner_location_auto_create #443
Changes from 1 commit
c7504bf
bc3ce5a
b427821
d220076
6022238
2ee12eb
f34ea01
44d4c33
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,6 @@ | ||
# -*- encoding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# This module copyright (C) 2015 Savoir-faire Linux | ||
# (<http://www.savoirfairelinux.com>). | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
# © 2015 Savoir-faire Linux | ||
# © 2018 brain-tec AG (Kumar Aberer <kumar.aberer@braintec-group.com>) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from . import models | ||
from .hooks import post_init_hook |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# © 2018 brain-tec AG (Kumar Aberer <kumar.aberer@braintec-group.com>) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import api, SUPERUSER_ID | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not sure if this is needed anymore. We have a sudo now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's needed to create a new Environment for the installation hook. Sudo does not help here |
||
import logging | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def post_init_hook(cr, _): | ||
"""Create custom location for existing partners""" | ||
with api.Environment.manage(): | ||
env = api.Environment(cr, SUPERUSER_ID, {}) | ||
|
||
logger.info('Create custom locations for partners') | ||
|
||
locations = env['stock.location'].search([]) | ||
partners = env['res.partner'].search([('is_company', '=', True)]) | ||
counter = 0 | ||
for partner in partners: | ||
if not locations.filtered(lambda l: l.partner_id == partner): | ||
logger.info('Create custom location for partner id=%s (%s/%s)' | ||
% (partner.id, counter, len(partners))) | ||
partner._create_main_partner_location() | ||
counter += 1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,6 @@ | ||
# -*- encoding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# This module copyright (C) 2015 Savoir-faire Linux | ||
# (<http://www.savoirfairelinux.com>). | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
# © 2015 Savoir-faire Linux | ||
# © 2018 brain-tec AG (Kumar Aberer <kumar.aberer@braintec-group.com>) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from openerp import models, fields, api | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. openerp => odoo |
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# © 2018 brain-tec AG (Kumar Aberer <kumar.aberer@braintec-group.com>) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from odoo import models, fields | ||
|
||
|
||
class ResConfigSettings(models.TransientModel): | ||
_inherit = 'res.config.settings' | ||
|
||
default_customer_location = fields.Many2one( | ||
related='company_id.default_customer_location') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. readonly=True |
||
default_supplier_location = fields.Many2one( | ||
related='company_id.default_supplier_location') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as above |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,6 @@ | ||
# -*- encoding: utf-8 -*- | ||
############################################################################## | ||
# | ||
# OpenERP, Open Source Management Solution | ||
# This module copyright (C) 2015 Savoir-faire Linux | ||
# (<http://www.savoirfairelinux.com>). | ||
# | ||
# This program is free software: you can redistribute it and/or modify | ||
# it under the terms of the GNU Affero General Public License as | ||
# published by the Free Software Foundation, either version 3 of the | ||
# License, or (at your option) any later version. | ||
# | ||
# This program is distributed in the hope that it will be useful, | ||
# but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
# GNU Affero General Public License for more details. | ||
# | ||
# You should have received a copy of the GNU Affero General Public License | ||
# along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
# | ||
############################################################################## | ||
# © 2015 Savoir-faire Linux | ||
# © 2018 brain-tec AG (Kumar Aberer <kumar.aberer@braintec-group.com>) | ||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). | ||
|
||
from openerp import models, fields, api, _ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. openerp => odoo |
||
|
||
|
@@ -32,10 +14,11 @@ class ResPartner(models.Model): | |
location_ids = fields.One2many( | ||
'stock.location', 'partner_id', string='Locations') | ||
|
||
@api.one | ||
@api.multi | ||
@api.depends('location_ids') | ||
def _compute_locations_count(self): | ||
self.locations_count = len(self.location_ids) | ||
for partner in self: | ||
partner.locations_count = len(partner.location_ids) | ||
|
||
@api.multi | ||
def button_locations(self): | ||
|
@@ -63,21 +46,24 @@ def get_main_location(self, usage): | |
return self.location_ids.filtered( | ||
lambda l: l.usage == usage and l.main_partner_location) | ||
|
||
@api.one | ||
@api.multi | ||
def _create_main_partner_location(self): | ||
if self.customer and self.property_stock_customer.partner_id != self: | ||
location_customer = ( | ||
self.get_main_location('customer') or | ||
self._create_main_location('customer')) | ||
for partner in self: | ||
if partner.customer and partner.property_stock_customer.\ | ||
partner_id != partner: | ||
location_customer = ( | ||
partner.get_main_location('customer') or | ||
partner._create_main_location('customer')) | ||
|
||
self.write({'property_stock_customer': location_customer}) | ||
partner.property_stock_customer = location_customer | ||
|
||
if self.supplier and self.property_stock_supplier.partner_id != self: | ||
location_supplier = ( | ||
self.get_main_location('supplier') or | ||
self._create_main_location('supplier')) | ||
if partner.supplier and partner.property_stock_supplier.\ | ||
partner_id != partner: | ||
location_supplier = ( | ||
partner.get_main_location('supplier') or | ||
partner._create_main_location('supplier')) | ||
|
||
self.write({'property_stock_supplier': location_supplier}) | ||
partner.property_stock_supplier = location_supplier | ||
|
||
@api.multi | ||
def _create_main_location(self, usage): | ||
|
@@ -97,7 +83,7 @@ def _create_main_location(self, usage): | |
'main_partner_location': True, | ||
}) | ||
|
||
@api.one | ||
@api.multi | ||
def _remove_locations(self): | ||
""" | ||
Unlink all locations related to the partner | ||
|
@@ -108,14 +94,15 @@ def _remove_locations(self): | |
by mistake. | ||
""" | ||
move_obj = self.env['stock.move'] | ||
for location in self.location_ids: | ||
moves = move_obj.search([ | ||
'|', | ||
('location_id', 'child_of', location.id), | ||
('location_dest_id', 'child_of', location.id), | ||
]) | ||
if not moves: | ||
location.unlink() | ||
for partner in self: | ||
for location in partner.location_ids: | ||
moves = move_obj.search([ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you have locations with huge moves, this could be a bottleneck. |
||
'|', | ||
('location_id', 'child_of', location.id), | ||
('location_dest_id', 'child_of', location.id), | ||
]) | ||
if not moves: | ||
location.unlink() | ||
|
||
@api.model | ||
def create(self, vals): | ||
|
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.
Remove empty key and flags.
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.
👍