Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions picking_analytic_compute/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: https://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3

========================
Picking Analytic Compute
========================

Picking Analytic Compute

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

To install this module, you need to:

#. Do this ...

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

To configure this module, you need to:

#. Go to ...

.. figure:: path/to/local/image.png
:alt: alternative description
:width: 600 px

Usage
=====

To use this module, you need to:

#. Go to ...

.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/{repo_id}/{branch}

.. repo_id is available in https://github.com/OCA/maintainer-tools/blob/master/tools/repos_with_ids.txt
.. branch is "8.0" for example

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

Bugs are tracked on `GitHub Issues
<https://github.com/OCA/{project_repo}/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://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_.

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

* Firstname Lastname <email.address@example.org>
* Second Person <second.person@example.org>

Funders
-------

The development of this module has been financially supported by:

* Company 1 name
* Company 2 name

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.
1 change: 1 addition & 0 deletions picking_analytic_compute/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
18 changes: 18 additions & 0 deletions picking_analytic_compute/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Copyright 2023 - TODAY, Escodoo
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

{
"name": "Picking Analytic Compute",
"summary": """
Picking Analytic Compute""",
"version": "14.0.1.0.0",
"license": "AGPL-3",
"author": "Escodoo,Odoo Community Association (OCA)",
"website": "https://github.com/OCA/account-analytic",
"depends": ["stock_analytic"],
"data": [
"views/stock_move_line_views.xml",
"views/stock_picking_views.xml",
"views/account_analytic.view.xml",
],
}
4 changes: 4 additions & 0 deletions picking_analytic_compute/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import account_analytic_line
from . import stock_move
from . import stock_picking
from . import stock_picking_type
13 changes: 13 additions & 0 deletions picking_analytic_compute/models/account_analytic_line.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Copyright 2023 - TODAY, Escodoo
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class AccountAnalyticLine(models.Model):

_inherit = "account.analytic.line"

picking_origin = fields.Many2one(
"stock.picking",
)
35 changes: 35 additions & 0 deletions picking_analytic_compute/models/stock_move.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# Copyright 2023 - TODAY, Escodoo
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import api, fields, models


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

picking_line_cost = fields.Float(
compute="_compute_picking_subtotal",
string="Subtotal",
readonly=True,
)

@api.depends("product_id", "quantity_done")
def _compute_picking_subtotal(self):
for line in self:
line.picking_line_cost = line.quantity_done * line.product_id.standard_price


class StockMoveLine(models.Model):

_inherit = "stock.move.line"

picking_line_cost = fields.Float(
compute="_compute_picking_subtotal",
string="Subtotal",
readonly=True,
)

@api.depends("product_id", "qty_done")
def _compute_picking_subtotal(self):
for line in self:
line.picking_line_cost = line.qty_done * line.product_id.standard_price
66 changes: 66 additions & 0 deletions picking_analytic_compute/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
# Copyright 2023 - TODAY, Escodoo
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class StockPicking(models.Model):

_inherit = "stock.picking"

has_analytic_line = fields.Boolean(compute="_compute_has_analytic_line")

def _create_analytic_entry(self):
for picking in self:
lines = picking.move_line_ids_without_package.filtered(
lambda line: line.analytic_account_id and line.qty_done > 0
)
for line in lines:
amount = line.product_id.standard_price * line.qty_done
if self.picking_type_id.compute_analytic_value == "credit":
self.env["account.analytic.line"].create(
{
"name": picking.name,
"account_id": line.analytic_account_id.id,
"amount": amount,
"unit_amount": line.qty_done,
"product_id": line.product_id.id,
"product_uom_id": line.product_id.uom_id.id,
"picking_origin": picking.id,
}
)
elif self.picking_type_id.compute_analytic_value == "debit":
self.env["account.analytic.line"].create(
{
"name": picking.name,
"account_id": line.analytic_account_id.id,
"amount": -amount,
"unit_amount": line.qty_done,
"product_id": line.product_id.id,
"product_uom_id": line.product_id.uom_id.id,
"picking_origin": picking.id,
}
)

def button_validate(self):
res = super(StockPicking, self).button_validate()
self._create_analytic_entry()
return res

def _compute_has_analytic_line(self):
for picking in self:
picking.has_analytic_line = bool(
self.env["account.analytic.line"].search_count(
[("picking_origin", "=", picking.id)]
)
)

def action_analytic_line_tree(self):
return {
"name": "Analytic Line Operations",
"type": "ir.actions.act_window",
"res_model": "account.analytic.line",
"view_mode": "tree",
"view_id": self.env.ref("analytic.view_account_analytic_line_tree").id,
"domain": [("picking_origin", "=", self.id)],
}
16 changes: 16 additions & 0 deletions picking_analytic_compute/models/stock_picking_type.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2023 - TODAY, Escodoo
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).

from odoo import fields, models


class StockPickingType(models.Model):

_inherit = "stock.picking.type"

compute_analytic_value = fields.Selection(
[
("debit", "Debit"), # Operation type debit
("credit", "Credit"), # Operation type credit
],
)
3 changes: 3 additions & 0 deletions picking_analytic_compute/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* `Escodoo <https://www.escodoo.com.br>`_:

* Kaynnan Lemes <kaynnan.lemes@escodoo.com.br>
Empty file.
11 changes: 11 additions & 0 deletions picking_analytic_compute/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
To use this module, you need to:

#. Go to Inventory.
#. Settings > Operations Type.
#. Select an Operation Type that you want to edit.
#. Locate the "Compute Analytic Value" field.
#. Set the type of operation to either "debit" or "credit." Leave it blank to disable this feature if desired.
#. Create a transfer using the edited Operation Type.
#. In the product lines of the transfer, set an "Account Analytic" for the products.
#. Once the transfer is validated, you will see a smart button that allows you to view the Debit or Credit lines associated with the Picking and Analytic Lines.
#. Click on the button to access and review the Debit or Credit lines for the current transfer.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions picking_analytic_compute/tests/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import test_picking_analytic_compute
Loading