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

[ADD] module price_multicompany #1

Closed
wants to merge 7 commits into from
Closed
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
11 changes: 11 additions & 0 deletions sale_check_multicompany/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# licence AGPL version 3 or later
# see licence in __openerp__.py or http://www.gnu.org/licenses/agpl-3.0.txt
# Copyright (C) 2014 Akretion (http://www.akretion.com).
# @author David BEAL <[email protected]>
#
##############################################################################

from . import sale
50 changes: 50 additions & 0 deletions sale_check_multicompany/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: David BEAL
# Copyright 2014 Akretion
#
# 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/>.
#
##############################################################################

{
'name': 'sale_check_multicompany',
'version': '0.1',
'category': '',
'sequence': 10,
'description': """
Check if data in quotation are linked to the same company
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': [
'sale',
],
'data': [
],
'demo': [
],
'installable': True,
'application': False,
'images': [
],
'css': [
],
'js': [
],
'qweb': [
],
}

40 changes: 40 additions & 0 deletions sale_check_multicompany/sale.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# licence AGPL version 3 or later
# see licence in __openerp__.py or http://www.gnu.org/licenses/agpl-3.0.txt
# Copyright (C) 2014 Akretion (http://www.akretion.com).
# @author David BEAL <[email protected]>
#
##############################################################################

from openerp.osv import orm
from openerp.tools.translate import _


class SaleOrder(orm.Model):
_inherit = 'sale.order'

def _check_pricelist(self, cr, uid, ids):
for elm in self.browse(cr, uid, ids):
if elm.pricelist_id:
if elm.company_id:
company = elm.company_id
else:
company_id = self.pool['res.company']._company_default_get(
cr, uid, 'sale.order')
company = self.pool['res.company'].browse(
cr, uid, company_id)
if elm.pricelist_id.company_id.id != company.id:
raise orm.except_orm(
Copy link
Member

Choose a reason for hiding this comment

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

This exception is not translated. By the way, I think the context should be added to the arguments.

_("Invalid Pricelist"),
_("The pricelist defined in this quotation is linked "
"to '%s' company\n"
"whereas the quotation is linked to '%s'\n"
"\nChoose a pricelist which match "
"to the company '%s'")
% (elm.pricelist_id.company_id.name,
company.name, company.name))
return True

_constraints = [(_check_pricelist, 'Error', ['pricelist_id'])]
11 changes: 11 additions & 0 deletions unshared_currency_multicompany/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# licence AGPL version 3 or later
# see licence in __openerp__.py or http://www.gnu.org/licenses/agpl-3.0.txt
# Copyright (C) 2014 Akretion (http://www.akretion.com).
# @author David BEAL <[email protected]>
#
##############################################################################

from . import currency
53 changes: 53 additions & 0 deletions unshared_currency_multicompany/__openerp__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Author: David BEAL
# Copyright 2014 Akretion
#
# 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/>.
#
##############################################################################

{
'name': 'Unshared Currency Multicompany',
'version': '0.1',
'category': 'Product',
'sequence': 10,
'summary': "Currency settings multicompany",
'description': """
This module should be used if your companies have their currencies non shared.
Currencies cannot be shared because 'res.currency.rate' doesn't have
a company_id field
This also implies that each company must have their own price lists
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': [
'product',
],
'data': [
],
'demo': [
],
'installable': True,
'application': False,
'images': [
],
'css': [
],
'js': [
],
'qweb': [
],
}
43 changes: 43 additions & 0 deletions unshared_currency_multicompany/currency.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# licence AGPL version 3 or later
# see licence in __openerp__.py or http://www.gnu.org/licenses/agpl-3.0.txt
# Copyright (C) 2014 Akretion (http://www.akretion.com).
# @author David BEAL <[email protected]>
#
##############################################################################

from openerp.osv import orm, fields


class ResCurrency(orm.Model):
_inherit = 'res.currency'

def name_get(self, cr, uid, ids, context=None):
""" If currencies are not shared and they have the same name,
then display have to distinguish them"""
result = []
for currency in self.browse(cr, uid, ids, context):
cpny_info = ''
if currency.company_id:
cpny_info = ' (%s)' % currency.company_id.name
result.append((currency.id, '%s%s' % (currency.name, cpny_info)))
return result


class ProductPriceType(orm.Model):
_inherit = 'product.price.type'

_columns = {
'currency_id': fields.property(
'res.currency',
relation='res.currency',
type='many2one',
string='Currency',
view_load=True,
required=True,
help="The currency the field is expressed in."
"Field redefined in field property "
"for multicompany purpose."),
}