Skip to content

Commit

Permalink
Add module l10n_ro_stock.
Browse files Browse the repository at this point in the history
  • Loading branch information
feketemihai committed Dec 9, 2019
1 parent 35d584c commit c25f655
Show file tree
Hide file tree
Showing 15 changed files with 278 additions and 0 deletions.
68 changes: 68 additions & 0 deletions l10n_ro_stock/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
.. image:: https://img.shields.io/badge/license-AGPL--3-blue.png
:target: https://www.gnu.org/licenses/agpl
:alt: License: AGPL-3

===============
Romania - Stock
===============

Ease the process of Consume and Usage Giving - adds location and picking types for every newly created warehouse.
You can also define the location merchandise type, if it's Merchandise in Store or Warehouse.

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

* clone the branch 11.0 of the repository https://github.com/OCA/l10n-romania
* add the path to this repository in your configuration (addons-path)
* update the module list
* search for "Romania - Stock" in your addons
* install the module

Usage
=====

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/177/11.0

Known issues / Roadmap
======================


Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/l10n-romania/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smash it by providing detailed and welcomed feedback.

Credits
=======

Images
------

* Odoo Community Association: `Icon <https://odoo-community.org/logo.png>`_.

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

* Fekete Mihai <feketemihai@gmail.com>
* Dorin Hongu <dhongu@gmail.com>

Do not contact contributors directly about support or help with technical issues.

Maintainer
----------

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

This module is maintained by the OCA.

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

To contribute to this module, please visit https://odoo-community.org.
3 changes: 3 additions & 0 deletions l10n_ro_stock/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# -*- coding: utf-8 -*-

from . import models
19 changes: 19 additions & 0 deletions l10n_ro_stock/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

{
"name": "Romania - Stock",
'category': 'Localization',
"depends": ['stock'],
'data': ['views/stock_warehouse_view.xml',
'views/stock_location_view.xml',],
'license': 'AGPL-3',
'version': '11.0.1.0.0',
'author': 'OdooERP Romania,'
'Dorin Hongu,'
'Forest and Biomass Romania,'
'Odoo Community Association (OCA)',
'website': 'https://github.com/OCA/l10n-romania',
'installable': True,
'development_status': 'Mature',
'maintainers': ['feketemihai'],
}
3 changes: 3 additions & 0 deletions l10n_ro_stock/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from . import stock_location
from . import stock_warehouse

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
19 changes: 19 additions & 0 deletions l10n_ro_stock/models/stock_location.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (C) 2016 Forest and Biomass Romania
# Copyright (C) 2018 Dorin Hongu <dhongu(@)gmail(.)com
# Copyright (C) 2019 OdooERP Romania
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import fields, models, _


class StockLocation(models.Model):
_inherit = "stock.location"

usage = fields.Selection(
selection_add=[('usage_giving', 'Usage Giving'),
('consume', 'Consume')])
merchandise_type = fields.Selection(
[("store", _("Store")),
("warehouse", _("Warehouse"))],
string="Merchandise type",
default="warehouse")
113 changes: 113 additions & 0 deletions l10n_ro_stock/models/stock_warehouse.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
# Copyright (C) 2016 Forest and Biomass Romania
# Copyright (C) 2018 Dorin Hongu <dhongu(@)gmail(.)com
# Copyright (C) 2019 OdooERP Romania
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).

from odoo import api, fields, models, _


class StockWarehouse(models.Model):
_inherit = "stock.warehouse"

wh_consume_loc_id = fields.Many2one(
'stock.location', 'Consume Location')
wh_usage_loc_id = fields.Many2one(
'stock.location', 'Usage Giving Location')
consume_type_id = fields.Many2one(
'stock.picking.type', 'Consume Type')
usage_type_id = fields.Many2one(
'stock.picking.type', 'Usage Giving Type')

# Change warehouse methods for create to add the consume and usage giving
# operations.

@api.model
def create(self, vals):
warehouse = super(StockWarehouse, self).create(vals)
stock_loc_obj = self.env['stock.location']
wh_consume_loc_vals = {'name': _('Consume'),
'active': True,
'usage': 'consume',
'company_id': warehouse.company_id.id,
'location_id': warehouse.view_location_id.id}
wh_usage_loc_vals = {'name': _('Usage'),
'active': True,
'usage': 'usage_giving',
'company_id': warehouse.company_id.id,
'location_id': warehouse.view_location_id.id}
warehouse.wh_consume_loc_id = stock_loc_obj.create(
wh_consume_loc_vals)
warehouse.wh_usage_loc_id = stock_loc_obj.create(
wh_usage_loc_vals)
# Update picking types location destination with the locations created
warehouse.consume_type_id.default_location_dest_id = \
warehouse.wh_consume_loc_id
warehouse.usage_type_id.default_location_dest_id = \
warehouse.wh_usage_loc_id
return warehouse

@api.model
def create_sequences_and_picking_types(self):
warehouse_data = super(
StockWarehouse, self).create_sequences_and_picking_types()
warehouse = self
seq_obj = self.env['ir.sequence']
picking_type_obj = self.env['stock.picking.type']
# create new sequences
cons_seq_id = seq_obj.sudo().create(
{'name': warehouse.name + _(' Sequence consume'),
'prefix': warehouse.code + '/CONS/', 'padding': 5})
usage_seq_id = seq_obj.sudo().create(
{'name': warehouse.name + _(' Sequence usage'),
'prefix': warehouse.code + '/USAGE/', 'padding': 5})

wh_stock_loc = warehouse.lot_stock_id
cons_stock_loc = warehouse.wh_consume_loc_id
usage_stock_loc = warehouse.wh_usage_loc_id

# order the picking types with a sequence allowing to have the
# following suit for each warehouse: reception, internal, pick, pack,
# ship.
max_sequence = self.env['stock.picking.type'].search_read(
[], ['sequence'], order='sequence desc')
max_sequence = max_sequence and max_sequence[0]['sequence'] or 0

# choose the next available color for the picking types of this
# warehouse
color = 0
# put flashy colors first
available_colors = [c % 9 for c in range(3, 12)]
all_used_colors = self.env['stock.picking.type'].search_read(
[('warehouse_id', '!=', False), ('color', '!=', False)],
['color'], order='color')
# don't use sets to preserve the list order
for x in all_used_colors:
if x['color'] in available_colors:
available_colors.remove(x['color'])
if available_colors:
color = available_colors[0]

consume_type_id = picking_type_obj.create(
{'name': _('Consume'),
'warehouse_id': warehouse.id,
'code': 'internal',
'sequence_id': cons_seq_id.id,
'default_location_src_id': wh_stock_loc.id,
'default_location_dest_id': cons_stock_loc.id,
'sequence': max_sequence + 1,
'color': color}
)
usage_type_id = picking_type_obj.create(
{'name': _('Usage'),
'warehouse_id': warehouse.id,
'code': 'internal',
'sequence_id': usage_seq_id.id,
'default_location_src_id': wh_stock_loc.id,
'default_location_dest_id': usage_stock_loc.id,
'sequence': max_sequence + 4,
'color': color}
)
vals = {'consume_type_id': consume_type_id.id,
'usage_type_id': usage_type_id.id, }
warehouse.write(vals)
return warehouse_data
Binary file added l10n_ro_stock/static/description/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
35 changes: 35 additions & 0 deletions l10n_ro_stock/views/stock_location_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_location_form" model="ir.ui.view">
<field name="name">stock.location.merchandise_type</field>
<field name="model">stock.location</field>
<field name="inherit_id" ref="stock.view_location_form"/>
<field name="arch" type="xml">
<field name="usage" position="after">
<field name="merchandise_type"/>
</field>
</field>
</record>

<record id="view_location_search" model="ir.ui.view">
<field name="name">stock.location.merchandise_type.search</field>
<field name="model">stock.location</field>
<field name="inherit_id" ref="stock.view_location_search"/>
<field name="arch" type="xml">
<field name="name" position="after">
<field name="merchandise_type"/>
</field>
</field>
</record>

<record id="view_location_tree2" model="ir.ui.view">
<field name="name">stock.location.merchandise_type.tree</field>
<field name="model">stock.location</field>
<field name="inherit_id" ref="stock.view_location_tree2"/>
<field name="arch" type="xml">
<field name="usage" position="after">
<field name="merchandise_type"/>
</field>
</field>
</record>
</odoo>
18 changes: 18 additions & 0 deletions l10n_ro_stock/views/stock_warehouse_view.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="view_warehouse" model="ir.ui.view">
<field name="name">stock.warehouse.consume</field>
<field name="model">stock.warehouse</field>
<field name="inherit_id" ref="stock.view_warehouse"/>
<field name="arch" type="xml">
<field name="wh_output_stock_loc_id" position="after">
<field name="wh_consume_loc_id" readonly="1"/>
<field name="wh_usage_loc_id" readonly="1"/>
</field>
<field name="out_type_id" position="after">
<field name="consume_type_id" readonly="1"/>
<field name="usage_type_id" readonly="1"/>
</field>
</field>
</record>
</odoo>

0 comments on commit c25f655

Please sign in to comment.