Skip to content

Commit

Permalink
[FIX] re-merge website multicompany modules
Browse files Browse the repository at this point in the history
closes #127

Signed-off-by: Juan José Scarafía <jjs@adhoc.com.ar>
  • Loading branch information
maq-adhoc committed Jun 22, 2023
1 parent ac07259 commit 82087f1
Show file tree
Hide file tree
Showing 11 changed files with 230 additions and 0 deletions.
57 changes: 57 additions & 0 deletions website_sale_multicompany/README.rst
@@ -0,0 +1,57 @@
.. |company| replace:: ADHOC SA

.. |company_logo| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-logo.png
:alt: ADHOC SA
:target: https://www.adhoc.com.ar

.. |icon| image:: https://raw.githubusercontent.com/ingadhoc/maintainer-tools/master/resources/adhoc-icon.png

.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

==============================
Website Sale Multicompany
==============================

# Con este modulo, cuando un usuario hace una compra en sitio web la misma se hará en la compañía por defecto que tenga seteada el usuario (company_id) en vez de la compañía del sitio web. Los métodos de envío y pago que se mostrarán serán lo de la compañía de la orden.

Installation
============

To install this module, you need to:

#. Only install the module

Configuration
=============

To configure this module, you need to:

#. Go to a Payment acquirer and select a journal that belongs to a different company than the Payment method

Usage
=====

To use this module, you need to:

#. For testing we recommend to create one database with "saas-provider" name and install "saas-provider" module

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: http://runbot.adhoc.com.ar/


Contributors
------------

Maintainer
----------

|company_logo|

This module is maintained by the |company|.

To contribute to this module, please visit https://www.adhoc.com.ar.

Este modulo es para que usuarios portal vean registros de las compañías que tienen asignadas como compañías permitidas (company_ids). Por defecto Odoo suele dejar ver solo lo de la compañía del sitio web.
1 change: 1 addition & 0 deletions website_sale_multicompany/__init__.py
@@ -0,0 +1 @@
from . import models
34 changes: 34 additions & 0 deletions website_sale_multicompany/__manifest__.py
@@ -0,0 +1,34 @@
##############################################################################
#
# Copyright (C) 2023 ADHOC SA (http://www.adhoc.com.ar)
# All Rights Reserved.
#
# 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': 'Website Sale multicompany',
'version': "16.0.1.0.0",
'author': 'ADHOC SA',
'website': 'www.adhoc.com.ar',
'license': 'AGPL-3',
'depends': [
'website_sale',
'website_multicompany',
],
'data': [],
'demo': [],
'installable': True,
'auto_install': False,
}
2 changes: 2 additions & 0 deletions website_sale_multicompany/models/__init__.py
@@ -0,0 +1,2 @@
from . import website
from . import sale_order
25 changes: 25 additions & 0 deletions website_sale_multicompany/models/sale_order.py
@@ -0,0 +1,25 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################

from odoo import models, fields


class SaleOrder(models.Model):

_inherit = 'sale.order'

# Quito el check company porque durante la creacion si el cliente tiene una cuenta analitica de otra
# company que la del website no puedo crear la orden
# https://github.com/odoo/odoo/blob/16.0/addons/sale/models/sale_order.py#L249
# (viene igual de 14.0 y no se toco aun en master)
analytic_account_id = fields.Many2one(
check_company=False, # Unrequired company
)

def _sale_get_order_company_fix(self):
vals = {}
if self.company_id != self.env.user.company_id:
vals['company_id'] = self.env.user.company_id.id
return vals
24 changes: 24 additions & 0 deletions website_sale_multicompany/models/website.py
@@ -0,0 +1,24 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################

import logging
from odoo import models, tools
from odoo.http import request


class Website(models.Model):

_inherit = 'website'

def sale_get_order(self, force_create=False, update_pricelist=False):
sale_order_sudo = super().sale_get_order(force_create, update_pricelist)
# _sale_get_order_company_fix modifica los valores company related de la orden
# Durante la creacion de la orden en el website la company siempre debe ser
# la del website por un Raise en el create(https://github.com/odoo/odoo/blob/16.0/addons/website_sale/models/sale_order.py#L38)
# por eso creo la orden y luego la modifico
vals = sale_order_sudo._sale_get_order_company_fix()
if vals:
sale_order_sudo.write(vals)
return sale_order_sudo
1 change: 1 addition & 0 deletions website_sale_stock_multicompany/__init__.py
@@ -0,0 +1 @@
from . import models
34 changes: 34 additions & 0 deletions website_sale_stock_multicompany/__manifest__.py
@@ -0,0 +1,34 @@
##############################################################################
#
# Copyright (C) 2023 ADHOC SA (http://www.adhoc.com.ar)
# All Rights Reserved.
#
# 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': 'Website Sale stock multicompany',
'version': "16.0.1.0.0",
'author': 'ADHOC SA',
'website': 'www.adhoc.com.ar',
'license': 'AGPL-3',
'depends': [
'website_sale_stock',
'website_sale_multicompany',
],
'data': [],
'demo': [],
'installable': True,
'auto_install': True,
}
2 changes: 2 additions & 0 deletions website_sale_stock_multicompany/models/__init__.py
@@ -0,0 +1,2 @@
from . import website
from . import sale_order
27 changes: 27 additions & 0 deletions website_sale_stock_multicompany/models/sale_order.py
@@ -0,0 +1,27 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################

from odoo import models, fields


class SaleOrder(models.Model):

_inherit = 'sale.order'

def _sale_get_order_company_fix(self):
vals = super()._sale_get_order_company_fix()
if self.warehouse_id.company_id != self.env.user.company_id:
vals['warehouse_id'] = self.website_id.with_context(company_fix=self.env.user.company_id.id)._get_warehouse_available()
return vals

def _get_warehouse_available(self):
self.ensure_one()
warehouse = super()._get_warehouse_available()
if warehouse:
warehouse_id = self.env['stock.warehouse'].browse(warehouse)
if warehouse_id.company_id != self.company_id:
warehouse = self.website_id.with_context(company_fix=self.env.user.company_id.id)._get_warehouse_available()

return warehouse
23 changes: 23 additions & 0 deletions website_sale_stock_multicompany/models/website.py
@@ -0,0 +1,23 @@
##############################################################################
# For copyright and license notices, see __manifest__.py file in module root
# directory
##############################################################################

import logging
from odoo import models, tools
from odoo.http import request


class Website(models.Model):

_inherit = 'website'


def _get_warehouse_available(self):
if self._context.get('company_fix'):
company = self._context.get('company_fix')
return (
self.env['ir.default'].get('sale.order', 'warehouse_id', company_id=company) or
self.env['stock.warehouse'].sudo().search([('company_id', '=', company)], limit=1).id
)
return super()._get_warehouse_available()

0 comments on commit 82087f1

Please sign in to comment.