Skip to content

Commit

Permalink
Merge PR #4 into 14.0
Browse files Browse the repository at this point in the history
Signed-off-by andhit-r
  • Loading branch information
ssi-bot committed Mar 26, 2024
2 parents ee1e50f + e308869 commit 2ece540
Show file tree
Hide file tree
Showing 17 changed files with 475 additions and 9 deletions.
47 changes: 47 additions & 0 deletions ssi_inventory_closing_queue/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

=======================
Inventory Closing Queue
=======================


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

To install this module, you need to:

1. Clone the branch 14.0 of the repository https://github.com/open-synergy/ssi-inventory-closing
2. Add the path to this repository in your configuration (addons-path)
3. Update the module list (Must be on developer mode)
4. Go to menu *Apps -> Apps -> Main Apps*
5. Search For *Inventory Closing*
6. Install the module

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

Bugs are tracked on `GitHub Issues
<https://github.com/open-synergy/ssi-inventory-closing/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
=======

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

* Miftahussalam <[email protected]>
* Michael Viriyananda <[email protected]>

Maintainer
----------

.. image:: https://simetri-sinergi.id/logo.png
:alt: PT. Simetri Sinergi Indonesia
:target: https://simetri-sinergi.id.com

This module is maintained by the PT. Simetri Sinergi Indonesia.
7 changes: 7 additions & 0 deletions ssi_inventory_closing_queue/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Copyright 2024 OpenSynergy Indonesia
# Copyright 2024 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import (
models,
)
28 changes: 28 additions & 0 deletions ssi_inventory_closing_queue/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2024 OpenSynergy Indonesia
# Copyright 2024 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

{
"name": "Inventory Closing Queue",
"version": "14.0.1.0.0",
"website": "https://simetri-sinergi.id",
"author": "PT. Simetri Sinergi Indonesia, OpenSynergy Indonesia",
"license": "AGPL-3",
"installable": True,
"depends": [
"queue_job_batch",
"ssi_inventory_closing",
"base_automation",
],
"data": [
"security/ir.model.access.csv",
"data/ir_actions_server_data.xml",
"data/base_automation_data.xml",
"data/policy_template_data.xml",
"views/inventory_closing_views.xml",
"views/inventory_closing_type_views.xml",
"views/stock_valuation_layer_views.xml",
],
"demo": [],
"images": [],
}
17 changes: 17 additions & 0 deletions ssi_inventory_closing_queue/data/base_automation_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<odoo>
<!-- Copyright 2022 OpenSynergy Indonesia
Copyright 2022 PT. Simetri Sinergi Indonesia
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<data>
<record id="inventory_closing_done" model="base.automation">
<field name="action_server_id" ref="inventory_closing_action_done" />
<field name="trigger">on_write</field>
<field
name="filter_pre_domain"
>[('state','=','confirm'), ('all_job_finished','=',False)]</field>
<field
name="filter_domain"
>[('state','=','confirm'), ('all_job_finished','=',True)]</field>
</record>
</data>
</odoo>
13 changes: 13 additions & 0 deletions ssi_inventory_closing_queue/data/ir_actions_server_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<odoo>
<!-- Copyright 2024 OpenSynergy Indonesia
Copyright 2024 PT. Simetri Sinergi Indonesia
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<data>
<record id="inventory_closing_action_done" model="ir.actions.server">
<field name="name">Action Done</field>
<field name="model_id" ref="model_inventory_closing" />
<field name="state">code</field>
<field name="code">records.action_done()</field>
</record>
</data>
</odoo>
25 changes: 25 additions & 0 deletions ssi_inventory_closing_queue/data/policy_template_data.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2023 OpenSynergy Indonesia
Copyright 2023 PT. Simetri Sinergi Indonesia
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>
<data>
<function name="write" model="ir.model.data">
<value
model="ir.model.data"
search="[('module', '=', 'ssi_inventory_closing'), ('name', '=', 'inventory_closing_policy_template_detail_cancel')]"
/>
<value eval="{'noupdate': False}" />
</function>
<record
id="ssi_inventory_closing.inventory_closing_policy_template_detail_cancel"
model="policy.template_detail"
>
<field name="restrict_additional" eval="1" />
<field name="additional_python_code">result = True
if document.state == "confirm" and not document.all_job_finished:
result = False
</field>
</record>
</data>
</odoo>
10 changes: 10 additions & 0 deletions ssi_inventory_closing_queue/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2024 OpenSynergy Indonesia
# Copyright 2024 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import (
stock_valuation_layer,
inventory_closing_type,
inventory_closing_queue_job_batch,
inventory_closing,
)
129 changes: 129 additions & 0 deletions ssi_inventory_closing_queue/models/inventory_closing.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Copyright 2024 OpenSynergy Indonesia
# Copyright 2024 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).


from odoo import _, api, fields, models

from odoo.addons.ssi_decorator import ssi_decorator


class InventoryClosing(models.Model):
_inherit = "inventory_closing"

_after_approved_method = False

queue_job_batch_ids = fields.One2many(
string="Queue Job Batch(s)",
comodel_name="inventory_closing_queue_job_batch",
inverse_name="inventory_closing_id",
)

@api.depends(
"queue_job_batch_ids",
"queue_job_batch_ids.job_batch_state",
)
def _compute_all_job_finished(self):
for rec in self:
job_not_finish_ids = rec.queue_job_batch_ids.filtered(
lambda x: x.job_batch_state != "finished"
)
if len(job_not_finish_ids) > 0:
rec.all_job_finished = False
else:
rec.all_job_finished = True

all_job_finished = fields.Boolean(
string="All Job Finished",
compute="_compute_all_job_finished",
store=True,
)

def _check_all_finished(self):
self.ensure_one()
result = True
for job_batch in self.queue_job_batch_ids:
if job_batch.job_batch_state != "finished":
result = False
break
return result

def _prepare_ic_queue_job_batch_data(self, batch_id):
data = {
"inventory_closing_id": self.id,
"job_batch_id": batch_id,
}
return data

def create_ic_queue_job_batch(self, batch_id):
self.ensure_one()
obj_ic_queue_job_batch = self.env["inventory_closing_queue_job_batch"]
obj_ic_queue_job_batch.create(self._prepare_ic_queue_job_batch_data(batch_id))
return True

def _create_aml_from_svl(self, svl_ids, index):
self.ensure_one()
queue_job_obj = self.env["queue.job"]
str_group = "[%s] Inventory Closing Batch for ID %s" % (str(index), self.id)
batch = self.env["queue.job.batch"].get_new_batch(str_group)
for svl in svl_ids:
description = "Create AML From SVL for ID %s" % (self.id)
job = (
svl.with_context(job_batch=batch)
.with_delay(description=_(description))
._create_accounting_entry()
)
criteria = [("uuid", "=", job.uuid)]
job_id = queue_job_obj.search(criteria, limit=1, order="id desc").id
svl.update(
{
"job_id": job_id,
}
)
batch.enqueue()
self.create_ic_queue_job_batch(batch.id)

@ssi_decorator.post_done_action()
def _01_update_svl_journal(self):
self.ensure_one()
return True

@ssi_decorator.post_done_action()
def _02_create_aml_from_svl(self):
self.ensure_one()
return True

@ssi_decorator.post_approve_action()
def _01_post_update_svl_journal(self):
self.ensure_one()
for move in self.stock_move_ids:
if not move.journal_id:
move.picking_id.write(
{
"journal_id": self.journal_id.id,
}
)

@ssi_decorator.post_approve_action()
def _02_post_create_aml_from_svl(self):
self.ensure_one()
svl_ids = self.stock_valuation_layer_ids.filtered(lambda x: not x.job_id)
if svl_ids:
batch_job_limit = self.type_id.batch_job_limit
for index, i in enumerate(range(0, len(svl_ids), batch_job_limit), start=1):
self._create_aml_from_svl(svl_ids[i : i + batch_job_limit], index)
else:
self._requeue_job_batch()

def _requeue_job_batch(self):
self.ensure_one()
svl_ids = self.stock_valuation_layer_ids.filtered(
lambda x: x.job_state != "done"
)
if svl_ids:
for svl in svl_ids:
svl.job_id.requeue()

def action_requeue(self):
for record in self.sudo():
record._requeue_job_batch()
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Copyright 2022 OpenSynergy Indonesia
# Copyright 2022 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
# pylint: disable=W0622
from odoo import api, fields, models


class InventoryClosingQueueJobBatch(models.Model):
_name = "inventory_closing_queue_job_batch"
_description = "Inventory Closing Queue Job Batch"

inventory_closing_id = fields.Many2one(
string="#Inventory Closing",
comodel_name="inventory_closing",
required=True,
ondelete="cascade",
)

@api.depends(
"job_id.result",
"job_id.exc_info",
)
def _get_job_result(self):
for rec in self:
rec.job_result = rec.job_id.result or rec.job_id.exc_info

job_batch_id = fields.Many2one(
comodel_name="queue.job.batch",
string="#Job Batch",
copy=False,
)
job_count = fields.Integer(
string="Job Count",
related="job_batch_id.job_count",
)
finished_job_count = fields.Float(
string="Completeness",
related="job_batch_id.finished_job_count",
)
job_batch_state = fields.Selection(
string="Status", related="job_batch_id.state", store=True
)
13 changes: 13 additions & 0 deletions ssi_inventory_closing_queue/models/inventory_closing_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2024 OpenSynergy Indonesia
# Copyright 2024 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models


class InventoryClosingType(models.Model):
_inherit = "inventory_closing_type"

batch_job_limit = fields.Integer(
string="Batch Job Limit",
default=100,
)
28 changes: 28 additions & 0 deletions ssi_inventory_closing_queue/models/stock_valuation_layer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2024 OpenSynergy Indonesia
# Copyright 2024 PT. Simetri Sinergi Indonesia
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import api, fields, models


class StockValuationLayer(models.Model):
_inherit = [
"stock.valuation.layer",
]

@api.depends(
"job_id.result",
"job_id.exc_info",
)
def _compute_job_result(self):
for rec in self:
rec.job_result = rec.job_id.result or rec.job_id.exc_info

job_id = fields.Many2one(
comodel_name="queue.job",
string="Job",
copy=False,
)
job_state = fields.Selection(string="Status", related="job_id.state", store=True)
job_result = fields.Text(
string="Result", compute="_compute_job_result", store=False
)
2 changes: 2 additions & 0 deletions ssi_inventory_closing_queue/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_inventory_closing_queue_job_batch_all,inventory_closing_queue_job_batch - all,model_inventory_closing_queue_job_batch,,1,0,0,0
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
26 changes: 26 additions & 0 deletions ssi_inventory_closing_queue/views/inventory_closing_type_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8" ?>
<!-- Copyright 2024 OpenSynergy Indonesia
Copyright 2024 PT. Simetri Sinergi Indonesia
License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -->
<odoo>

<record id="inventory_closing_type_view_form" model="ir.ui.view">
<field name="name">inventory_closing_type.queue - form</field>
<field name="model">inventory_closing_type</field>
<field
name="inherit_id"
ref="ssi_inventory_closing.inventory_closing_type_view_form"
/>
<field name="arch" type="xml">
<data>
<xpath expr="//page[last()]" position="after">
<page name="queue" string="Queue Job">
<group name="queue" colspan="4" col="2" groups="base.group_system">
<field name="batch_job_limit" />
</group>
</page>
</xpath>
</data>
</field>
</record>
</odoo>
Loading

0 comments on commit 2ece540

Please sign in to comment.