Add modules stock_user_default_warehouse_base, stock_user_default_warehouse_purchase and stock_user_default_warehouse_sale

This commit is contained in:
Alexis de Lattre
2017-07-19 15:16:28 +02:00
parent d56acb4a86
commit 61d576451e
12 changed files with 194 additions and 0 deletions

View File

@@ -0,0 +1,4 @@
# -*- coding: utf-8 -*-
from . import users
from . import wizard

View File

@@ -0,0 +1,30 @@
# -*- coding: utf-8 -*-
# © 2017 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Default Stock Warehouse on User',
'version': '10.0.1.0.0',
'category': 'Inventory, Logistics, Warehousing',
'license': 'AGPL-3',
'summary': 'Configure a default warehouse on user',
'description': """
Default Warehouse on User
=========================
With this module, you will be able to configure a default warehouse in the preferences of the user.
This module doesn't do anything by itself. It should be used together with stock_user_default_warehouse_sale and/or stock_user_default_warehouse_purchase.
This module has been written by Alexis de Lattre from Akretion
<alexis.delattre@akretion.com>.
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['stock'],
'data': [
'users_view.xml',
],
'installable': True,
}

View File

@@ -0,0 +1,16 @@
# -*- coding: utf-8 -*-
# © 2017 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields
class ResUsers(models.Model):
_inherit = 'res.users'
context_default_warehouse_id = fields.Many2one(
'stock.warehouse', string='Default Warehouse', company_dependent=True,
help=u"Default warehouse for sale orders (if the module "
"stock_user_default_warehouse_sale is installed) and purchase orders "
"(if the module stock_user_default_warehouse_purchase is installed).")

View File

@@ -0,0 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_users_form" model="ir.ui.view">
<field name="name">default_stock_warehouse.res.users.form</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form"/>
<field name="arch" type="xml">
<group name="preferences" position="inside">
<field name="context_default_warehouse_id"/>
</group>
</field>
</record>
<record id="view_users_form_simple_modif" model="ir.ui.view">
<field name="name">default_stock_warehouse.preferences.res.users.form</field>
<field name="model">res.users</field>
<field name="inherit_id" ref="base.view_users_form_simple_modif"/>
<field name="arch" type="xml">
<group name="preferences" position="inside">
<field name="context_default_warehouse_id" readonly="0"/>
</group>
</field>
</record>
</odoo>

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import stock_change_product_qty

View File

@@ -0,0 +1,18 @@
# -*- coding: utf-8 -*-
# © 2017 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, api
class StockChangeProductQty(models.TransientModel):
_inherit = 'stock.change.product.qty'
@api.model
def default_get(self, fields_list):
res = super(StockChangeProductQty, self).default_get(fields_list)
if self.env.user.context_default_warehouse_id:
res['location_id'] = self.env.user.context_default_warehouse_id.\
lot_stock_id.id
return res

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import purchase

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# © 2017 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Default Warehouse on User (Purchase)',
'version': '10.0.1.0.0',
'category': 'Purchases',
'license': 'AGPL-3',
'summary': "Use the users's default warehouse on purchase orders",
'description': """
Default Warehouse on User (Purchase)
====================================
The default warehouse configured in the preferences of the user will be used by default for the picking type on purchase orders.
This module has been written by Alexis de Lattre from Akretion
<alexis.delattre@akretion.com>.
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['purchase', 'stock_user_default_warehouse_base'],
'installable': True,
}

View File

@@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# © 2017 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields, api
class PurchaseOrder(models.Model):
_inherit = 'purchase.order'
@api.model
def _default_pref_picking_type(self):
default_in_type = self.env.user.context_default_warehouse_id.in_type_id
if default_in_type:
return default_in_type.id
return self._default_picking_type
picking_type_id = fields.Many2one(default=_default_pref_picking_type)

View File

@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-
from . import sale

View File

@@ -0,0 +1,25 @@
# -*- coding: utf-8 -*-
# © 2017 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Default Warehouse on User (Sale)',
'version': '10.0.1.0.0',
'category': 'Sale Management',
'license': 'AGPL-3',
'summary': "Use the users's default warehouse on sale orders",
'description': """
Default Warehouse on User (Sale)
================================
The default warehouse configured in the preferences of the user will be used by default on sale orders.
This module has been written by Alexis de Lattre from Akretion
<alexis.delattre@akretion.com>.
""",
'author': 'Akretion',
'website': 'http://www.akretion.com',
'depends': ['sale_stock', 'stock_user_default_warehouse_base'],
'installable': True,
}

View File

@@ -0,0 +1,20 @@
# -*- coding: utf-8 -*-
# © 2017 Akretion (http://www.akretion.com)
# @author Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields, api
class SaleOrder(models.Model):
_inherit = 'sale.order'
@api.model
def _default_warehouse_id(self):
warehouse = self.env.user.context_default_warehouse_id
if not warehouse:
warehouse = self.env['stock.warehouse'].search(
[('company_id', '=', self.env.user.company_id.id)], limit=1)
return warehouse
warehouse_id = fields.Many2one(default=_default_warehouse_id)