Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[16.0][MIG] sale_stock_picking_analytic: Migration to 16.0 #338

Merged
merged 6 commits into from
Jan 13, 2025
Merged
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
31 changes: 31 additions & 0 deletions sale_stock_picking_analytic/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
.. 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

=========================================
Sales and Warehouse Management - Analytic
=========================================

In order to improve zip object usability, make related fields to city and allow
filtering and grouping by them:

* state
* country

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

Bugs are tracked on `GitHub Issues
<https://github.com/avanzosc/odoo-addons/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
------------
* Ana Juaristi <[email protected]>
* Oihane Crucelaegui <[email protected]>

Do not contact contributors directly about support or help with technical issues.
1 change: 1 addition & 0 deletions sale_stock_picking_analytic/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
22 changes: 22 additions & 0 deletions sale_stock_picking_analytic/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2022 Oihane Crucelaegui - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

{
"name": "Sales and Warehouse Management - Analytic",
"summary": "Glue module between sale_stock and stock_picking_analytic",
"version": "16.0.1.0.0",
"category": "Hidden",
"license": "AGPL-3",
"author": "AvanzOSC",
"website": "https://github.com/avanzosc/sale-addons",
"depends": [
"sale_stock",
"stock_picking_analytic",
],
"data": [
"views/sale_order_views.xml",
"views/stock_picking_views.xml",
],
"installable": True,
"auto_install": True,
}
65 changes: 65 additions & 0 deletions sale_stock_picking_analytic/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_stock_picking_analytic
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-22 09:05+0000\n"
"PO-Revision-Date: 2022-11-22 09:05+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: sale_stock_picking_analytic
#: model_terms:ir.ui.view,arch_db:sale_stock_picking_analytic.view_picking_form
msgid "Analytic movements"
msgstr "Mvtos. Analítica"

#. module: sale_stock_picking_analytic
#: model:ir.model.fields,field_description:sale_stock_picking_analytic.field_stock_picking__count_analytic_lines
msgid "Count analytic lines"
msgstr "Contaldor líneas analítica"

#. module: sale_stock_picking_analytic
#: model:ir.model.fields,field_description:sale_stock_picking_analytic.field_sale_order__display_name
#: model:ir.model.fields,field_description:sale_stock_picking_analytic.field_stock_picking__display_name
msgid "Display Name"
msgstr "Nombre mostrado"

#. module: sale_stock_picking_analytic
#: model:ir.actions.server,name:sale_stock_picking_analytic.action_create_analytic_line_from_out_picking
msgid "Generate movement analytics in out pickings"
msgstr "Generar mvto. analítica en albaranes de salida"

#. module: sale_stock_picking_analytic
#: model:ir.model.fields,field_description:sale_stock_picking_analytic.field_sale_order__id
#: model:ir.model.fields,field_description:sale_stock_picking_analytic.field_stock_picking__id
msgid "ID"
msgstr ""

#. module: sale_stock_picking_analytic
#: model:ir.model.fields,field_description:sale_stock_picking_analytic.field_sale_order____last_update
#: model:ir.model.fields,field_description:sale_stock_picking_analytic.field_stock_picking____last_update
msgid "Last Modified on"
msgstr "Última modificación el"

#. module: sale_stock_picking_analytic
#: model:ir.actions.server,name:sale_stock_picking_analytic.action_put_analytic_in_out_picking_from_sale
msgid "Put analytic account in pickings"
msgstr "Poner cta. analítica en albaranes"

#. module: sale_stock_picking_analytic
#: model:ir.model,name:sale_stock_picking_analytic.model_sale_order
msgid "Sales Order"
msgstr "Pedido de venta"

#. module: sale_stock_picking_analytic
#: model:ir.model,name:sale_stock_picking_analytic.model_stock_picking
msgid "Transfer"
msgstr "Albarán"

64 changes: 64 additions & 0 deletions sale_stock_picking_analytic/i18n/sale_stock_picking_analytic.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * sale_stock_picking_analytic
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2022-11-22 09:05+0000\n"
"PO-Revision-Date: 2022-11-22 09:05+0000\n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: sale_stock_picking_analytic
#: model_terms:ir.ui.view,arch_db:sale_stock_picking_analytic.view_picking_form
msgid "Analytic movements"
msgstr ""

#. module: sale_stock_picking_analytic
#: model:ir.model.fields,field_description:sale_stock_picking_analytic.field_stock_picking__count_analytic_lines
msgid "Count analytic lines"
msgstr ""

#. module: sale_stock_picking_analytic
#: model:ir.model.fields,field_description:sale_stock_picking_analytic.field_sale_order__display_name
#: model:ir.model.fields,field_description:sale_stock_picking_analytic.field_stock_picking__display_name
msgid "Display Name"
msgstr ""

#. module: sale_stock_picking_analytic
#: model:ir.actions.server,name:sale_stock_picking_analytic.action_create_analytic_line_from_out_picking
msgid "Generate movement analytics in out pickings"
msgstr ""

#. module: sale_stock_picking_analytic
#: model:ir.model.fields,field_description:sale_stock_picking_analytic.field_sale_order__id
#: model:ir.model.fields,field_description:sale_stock_picking_analytic.field_stock_picking__id
msgid "ID"
msgstr ""

#. module: sale_stock_picking_analytic
#: model:ir.model.fields,field_description:sale_stock_picking_analytic.field_sale_order____last_update
#: model:ir.model.fields,field_description:sale_stock_picking_analytic.field_stock_picking____last_update
msgid "Last Modified on"
msgstr ""

#. module: sale_stock_picking_analytic
#: model:ir.actions.server,name:sale_stock_picking_analytic.action_put_analytic_in_out_picking_from_sale
msgid "Put analytic account in pickings"
msgstr ""

#. module: sale_stock_picking_analytic
#: model:ir.model,name:sale_stock_picking_analytic.model_sale_order
msgid "Sales Order"
msgstr ""

#. module: sale_stock_picking_analytic
#: model:ir.model,name:sale_stock_picking_analytic.model_stock_picking
msgid "Transfer"
msgstr ""
2 changes: 2 additions & 0 deletions sale_stock_picking_analytic/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import sale_order
from . import stock_picking
27 changes: 27 additions & 0 deletions sale_stock_picking_analytic/models/sale_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2022 Alfredo de la Fuente - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).

from odoo import models


class SaleOrder(models.Model):
_inherit = "sale.order"

def action_confirm(self):
result = super().action_confirm()
for sale in self.filtered(lambda x: x.analytic_account_id):
pickings = sale.picking_ids.filtered(lambda z: not z.analytic_account_id)
if pickings:
pickings.write({"analytic_account_id": sale.analytic_account_id})
return result

def put_analytic_in_out_picking_from_sale(self):
sales = self.filtered(
lambda x: x.analytic_account_id and x.state not in ("draft", "cancel")
)
for sale in sales:
pickings = sale.picking_ids.filtered(
lambda z: not z.analytic_account_id and z.state == "done"
)
if pickings:
pickings.write({"analytic_account_id": sale.analytic_account_id})
62 changes: 62 additions & 0 deletions sale_stock_picking_analytic/models/stock_picking.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Copyright 2022 Alfredo de la Fuente - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import fields, models
from odoo.models import expression
from odoo.tools.safe_eval import safe_eval


class StockPicking(models.Model):
_inherit = "stock.picking"

count_analytic_lines = fields.Integer(
string="Count analytic lines", compute="_compute_count_analytic_lines"
)

def _compute_count_analytic_lines(self):
for picking in self:
picking.count_analytic_lines = len(picking._get_count_analytic_lines())

def action_analytic_movements_from_picking(self):
lines = self._get_count_analytic_lines()
if lines:
action = self.env.ref("analytic.account_analytic_line_action_entries")
action_dict = action and action.read()[0]
action_dict["context"] = safe_eval(action_dict.get("context", "{}"))
domain = expression.AND(
[[("id", "in", lines.ids)], safe_eval(action.domain or "[]")]
)
action_dict.update({"domain": domain})
return action_dict

def _get_count_analytic_lines(self):
lines = self.env["account.analytic.line"]
if self.analytic_account_id:
cond = [
("account_id", "=", self.analytic_account_id.id),
("partner_id", "=", self.partner_id.id),
]
lines = self.env["account.analytic.line"].search(cond)
return lines

def create_analytic_line_from_out_picking(self):
pickings = self.filtered(
lambda x: x.picking_type_code == "outgoing"
and x.state == "done"
and x.analytic_account_id
)
for picking in pickings:
for move in picking.move_ids_without_package:
picking = move.picking_id
if move.quantity_done > 0:
cond = [
("stock_move_id", "=", move.id),
("account_id", "=", picking.analytic_account_id.id),
("partner_id", "=", picking.partner_id.id),
("product_id", "=", move.product_id.id),
("unit_amount", "<", 0),
]
old_move = self.env["account.analytic.line"].search(cond, limit=1)
if not old_move:
vals = move._prepare_data_for_create_analytic_line()
if vals:
self.env["account.analytic.line"].create(vals)
12 changes: 12 additions & 0 deletions sale_stock_picking_analytic/views/sale_order_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record id="action_put_analytic_in_out_picking_from_sale" model="ir.actions.server">
<field name="name">Put analytic account in pickings</field>
<field name="model_id" ref="sale.model_sale_order" />
<field name="binding_model_id" ref="sale.model_sale_order" />
<field name="state">code</field>
<field name="code">
records.put_analytic_in_out_picking_from_sale()
</field>
</record>
</odoo>
33 changes: 33 additions & 0 deletions sale_stock_picking_analytic/views/stock_picking_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="UTF-8" ?>
<odoo>
<record model="ir.ui.view" id="view_picking_form">
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_form" />
<field name="arch" type="xml">
<xpath expr="//div[@name='button_box']" position="inside">
<button
type="object"
class="oe_stat_button"
name="action_analytic_movements_from_picking"
icon="fa-sitemap"
>
<field
name="count_analytic_lines"
widget="statinfo"
string="Analytic movements"
/>
</button>
</xpath>
</field>
</record>

<record id="action_create_analytic_line_from_out_picking" model="ir.actions.server">
<field name="name">Generate movement analytics in out pickings</field>
<field name="model_id" ref="stock.model_stock_picking" />
<field name="binding_model_id" ref="stock.model_stock_picking" />
<field name="state">code</field>
<field name="code">
records.create_analytic_line_from_out_picking()
</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions setup/sale_stock_picking_analytic/setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import setuptools

setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Loading