Skip to content

Commit

Permalink
Merge PR #173 into 12.0
Browse files Browse the repository at this point in the history
Signed-off-by aheficent
  • Loading branch information
OCA-git-bot committed Nov 28, 2019
2 parents 4f9732f + 4537e18 commit 1d844ba
Show file tree
Hide file tree
Showing 17 changed files with 996 additions and 26 deletions.
16 changes: 8 additions & 8 deletions account_operating_unit/models/account_invoice.py
Expand Up @@ -10,14 +10,14 @@
class AccountInvoice(models.Model):
_inherit = "account.invoice"

operating_unit_id = fields.Many2one('operating.unit', 'Operating Unit',
default=lambda self:
self.env['res.users'].
operating_unit_default_get(self._uid),
domain="[('user_ids', '=', uid)]",
readonly=True,
states={'draft': [('readonly',
False)]})
operating_unit_id = fields.Many2one(
comodel_name='operating.unit',
string='Operating Unit',
default=lambda self: self.env['res.users'].operating_unit_default_get(
self._uid),
domain="[('user_ids', '=', uid)]",
readonly=True,
states={'draft': [('readonly', False)]})

@api.onchange('operating_unit_id')
def _onchange_operating_unit(self):
Expand Down
12 changes: 6 additions & 6 deletions account_operating_unit/models/account_journal.py
Expand Up @@ -9,12 +9,12 @@
class AccountJournal(models.Model):
_inherit = "account.journal"

operating_unit_id = fields.Many2one(comodel_name='operating.unit',
string='Operating Unit',
domain="[('user_ids', '=', uid)]",
help="Operating Unit that will be "
"used in payments, when this "
"journal is used.")
operating_unit_id = fields.Many2one(
comodel_name='operating.unit',
string='Operating Unit',
domain="[('user_ids', '=', uid)]",
help="Operating Unit that will be used in payments, "
"when this journal is used.")

@api.multi
@api.constrains('type')
Expand Down
17 changes: 10 additions & 7 deletions account_operating_unit/models/account_move.py
Expand Up @@ -9,8 +9,10 @@
class AccountMoveLine(models.Model):
_inherit = "account.move.line"

operating_unit_id = fields.Many2one('operating.unit', 'Operating Unit',
domain="[('user_ids', '=', uid)]",)
operating_unit_id = fields.Many2one(
comodel_name='operating.unit',
string='Operating Unit',
domain="[('user_ids', '=', uid)]",)

@api.model
def create(self, vals):
Expand Down Expand Up @@ -54,11 +56,12 @@ def _check_move_operating_unit(self):
class AccountMove(models.Model):
_inherit = "account.move"

operating_unit_id = fields.Many2one('operating.unit',
'Default operating unit',
domain="[('user_ids', '=', uid)]",
help="This operating unit will "
"be defaulted in the move lines.")
operating_unit_id = fields.Many2one(
comodel_name='operating.unit',
string='Default operating unit',
domain="[('user_ids', '=', uid)]",
help="This operating unit will be "
"defaulted in the move lines.")

@api.multi
def _prepare_inter_ou_balancing_move_line(self, move, ou_id,
Expand Down
2 changes: 1 addition & 1 deletion account_operating_unit/models/account_payment.py
Expand Up @@ -23,7 +23,7 @@ def _compute_operating_unit_id(self):
def _get_counterpart_move_line_vals(self, invoice=False):
res = super(AccountPayment,
self)._get_counterpart_move_line_vals(invoice=invoice)
if len(invoice) == 1:
if invoice and len(invoice) == 1:
res['operating_unit_id'] = invoice.operating_unit_id.id or False
else:
res['operating_unit_id'] = self.operating_unit_id.id or False
Expand Down
85 changes: 85 additions & 0 deletions stock_account_operating_unit/README.rst
@@ -0,0 +1,85 @@
=======================================
Stock account moves with Operating Unit
=======================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png
:target: https://odoo-community.org/page/development-status
:alt: Beta
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Foperating--unit-lightgray.png?logo=github
:target: https://github.com/OCA/operating-unit/tree/12.0/stock_account_operating_unit
:alt: OCA/operating-unit
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/operating-unit-12-0/operating-unit-12-0-stock_account_operating_unit
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/213/12.0
:alt: Try me on Runbot

|badge1| |badge2| |badge3| |badge4| |badge5|

This module introduces the following features:

- Creates account move lines when stock moves are posted between internal
locations within the same company, but different OU’s.

**Table of contents**

.. contents::
:local:

Usage
=====

Create stock moves between internal locations within the same company, but
different OU’s. The journal entries are created and they are self-balanced
within the OU when the journal entries are posted

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/operating-unit/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed
`feedback <https://github.com/OCA/operating-unit/issues/new?body=module:%20stock_account_operating_unit%0Aversion:%2012.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

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

Credits
=======

Authors
~~~~~~~

* Eficent Business and IT Consulting Services S.L.
* Serpent Consulting Services Pvt. Ltd.

Contributors
~~~~~~~~~~~~

* Eficent Business and IT Consulting Services S.L. <contact@eficent.com>
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>

Maintainers
~~~~~~~~~~~

This module is maintained by the OCA.

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

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.

This module is part of the `OCA/operating-unit <https://github.com/OCA/operating-unit/tree/12.0/stock_account_operating_unit>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
2 changes: 2 additions & 0 deletions stock_account_operating_unit/__init__.py
@@ -0,0 +1,2 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import model
23 changes: 23 additions & 0 deletions stock_account_operating_unit/__manifest__.py
@@ -0,0 +1,23 @@
# © 2019 Eficent Business and IT Consulting Services S.L.
# - Jordi Ballester Alomar
# © 2019 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).

{
"name": "Stock account moves with Operating Unit",
"summary": "Create journal entries in moves between internal locations "
"with different operating units.",
"version": "12.0.1.0.0",
"category": "Generic Modules/Sales & Purchases",
"author": "Eficent Business and IT Consulting Services S.L., "
"Serpent Consulting Services Pvt. Ltd.,"
"Odoo Community Association (OCA)",
"license": "LGPL-3",
"website": "https://github.com/OCA/operating-unit",
"depends": [
'stock_operating_unit',
'account_operating_unit',
"stock_account"
],
"installable": True,
}
2 changes: 2 additions & 0 deletions stock_account_operating_unit/model/__init__.py
@@ -0,0 +1,2 @@
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from . import stock_move
90 changes: 90 additions & 0 deletions stock_account_operating_unit/model/stock_move.py
@@ -0,0 +1,90 @@
# © 2019 Eficent Business and IT Consulting Services S.L.
# - Jordi Ballester Alomar
# © 2019 Serpent Consulting Services Pvt. Ltd. - Sudhir Arya
# License LGPL-3.0 or later (https://www.gnu.org/licenses/lgpl.html).
from odoo import _, api, exceptions, models


class StockMove(models.Model):
_inherit = "stock.move"

def _generate_valuation_lines_data(
self, partner_id, qty, debit_value, credit_value, debit_account_id,
credit_account_id):
res = super(StockMove, self)._generate_valuation_lines_data(
partner_id, qty, debit_value, credit_value, debit_account_id,
credit_account_id)
if res:
debit_line_vals = res.get('debit_line_vals')
credit_line_vals = res.get('credit_line_vals')
price_diff_line_vals = res.get('price_diff_line_vals', {})

if (
self.operating_unit_id and self.operating_unit_dest_id and
self.operating_unit_id != self.operating_unit_dest_id and
debit_line_vals['account_id'] != credit_line_vals['account_id']
):
raise exceptions.UserError(
_('You cannot create stock moves involving separate source'
' and destination accounts related to different '
'operating units.')
)

if (not self.operating_unit_dest_id
and not self.operating_unit_id):
ou_id = self.picking_id.picking_type_id.warehouse_id. \
operating_unit_id.id
else:
ou_id = False

debit_line_vals['operating_unit_id'] = ou_id or \
self.operating_unit_dest_id.id or self.operating_unit_id.id
credit_line_vals['operating_unit_id'] = ou_id or \
self.operating_unit_id.id or self.operating_unit_dest_id.id
rslt = {'credit_line_vals': credit_line_vals,
'debit_line_vals': debit_line_vals}
if price_diff_line_vals:
price_diff_line_vals['operating_unit_id'] = ou_id or \
self.operating_unit_id.id or self.operating_unit_dest_id.id
rslt['price_diff_line_vals'] = price_diff_line_vals
return rslt
return res

@api.multi
def _action_done(self):
"""
Generate accounting moves if the product being moved is subject
to real_time valuation tracking,
and the source or destination location are
a transit location or is outside of the company or the source or
destination locations belong to different operating units.
"""
res = super(StockMove, self)._action_done()
for move in self:

if move.product_id.valuation == 'real_time':
# Inter-operating unit moves do not accept to
# from/to non-internal location
if (move.location_id.company_id and
move.location_id.company_id ==
move.location_dest_id.company_id and
move.operating_unit_id != move.operating_unit_dest_id):
(journal_id, acc_src, acc_dest, acc_valuation) = \
move._get_accounting_data_for_valuation()

move_lines = move._prepare_account_move_line(
move.product_qty,
move.product_id.standard_price,
acc_valuation,
acc_valuation)
am = self.env["account.move"].with_context(
force_company=move.location_id.company_id.id,
company_id=move.company_id.id).create({
'journal_id': journal_id,
'line_ids': move_lines,
'company_id': move.company_id.id,
'ref': move.picking_id and move.picking_id.name,
'stock_move_id': self.id,
})
am.post()
return res
11 changes: 11 additions & 0 deletions stock_account_operating_unit/readme/CONFIGURATION.rst
@@ -0,0 +1,11 @@
If your company is required to generate a balanced balance sheet by
operating unit you can specify at company level that operating units should
be self-balanced, and then indicate a self-balancing clearing account.

#. Create an account for "Inter-OU Clearing" of type Regular.
#. Go to *Settings / Companies / Configuration* and:

* Set the "Operating Units are self-balanced" checkbox.
* Set the "Inter-OU Clearing" account in "Inter-operating unit clearing
account" field.
#. Assign Operating Unit in Accounts.
2 changes: 2 additions & 0 deletions stock_account_operating_unit/readme/CONTRIBUTORS.rst
@@ -0,0 +1,2 @@
* Eficent Business and IT Consulting Services S.L. <contact@eficent.com>
* Serpent Consulting Services Pvt. Ltd. <support@serpentcs.com>
4 changes: 4 additions & 0 deletions stock_account_operating_unit/readme/DESCRIPTION.rst
@@ -0,0 +1,4 @@
This module introduces the following features:

- Creates account move lines when stock moves are posted between internal
locations within the same company, but different OU’s.
3 changes: 3 additions & 0 deletions stock_account_operating_unit/readme/USAGE.rst
@@ -0,0 +1,3 @@
Create stock moves between internal locations within the same company, but
different OU’s. The journal entries are created and they are self-balanced
within the OU when the journal entries are posted

0 comments on commit 1d844ba

Please sign in to comment.