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

[15.0][MIG] stock_landed_costs_purchase_auto: Migration to 15.0 #1212

Merged
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
6 changes: 6 additions & 0 deletions setup/stock_landed_costs_purchase_auto/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,
)
96 changes: 96 additions & 0 deletions stock_landed_costs_purchase_auto/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
================================
Stock landed costs purchase auto
================================

.. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! 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-AGPL--3-blue.png
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fstock--logistics--workflow-lightgray.png?logo=github
:target: https://github.com/OCA/stock-logistics-workflow/tree/15.0/stock_landed_costs_purchase_auto
:alt: OCA/stock-logistics-workflow
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/stock-logistics-workflow-15-0/stock-logistics-workflow-15-0-stock_landed_costs_purchase_auto
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runbot-Try%20me-875A7B.png
:target: https://runbot.odoo-community.org/runbot/154/15.0
:alt: Try me on Runbot

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

This addon will auto-create a stock landed cost linked to the purchase order when it is
confirmed.

**Table of contents**

.. contents::
:local:

Usage
=====

#. Go to Purchase> Orders > Requests for Quotation.
#. Create an order with any product.
#. Confirm Order.
#. Go to "Receipt" smart-button.
#. Validate picking.
#. Go to Inventory > Operations > Landed Costs.
#. There will be a record related to the purchase order and the validated picking.

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

Bugs are tracked on `GitHub Issues <https://github.com/OCA/stock-logistics-workflow/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/stock-logistics-workflow/issues/new?body=module:%20stock_landed_costs_purchase_auto%0Aversion:%2015.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
~~~~~~~

* Tecnativa

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

* `Tecnativa <https://www.tecnativa.com>`_

* Pedro M. Baeza
* Víctor Martínez

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.

.. |maintainer-victoralmau| image:: https://github.com/victoralmau.png?size=40px
:target: https://github.com/victoralmau
:alt: victoralmau

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-victoralmau|

This module is part of the `OCA/stock-logistics-workflow <https://github.com/OCA/stock-logistics-workflow/tree/15.0/stock_landed_costs_purchase_auto>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions stock_landed_costs_purchase_auto/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
14 changes: 14 additions & 0 deletions stock_landed_costs_purchase_auto/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
{
"name": "Stock landed costs purchase auto",
"version": "15.0.1.0.0",
"category": "Inventory",
"website": "https://github.com/OCA/stock-logistics-workflow",
"author": "Tecnativa, Odoo Community Association (OCA)",
"license": "AGPL-3",
"depends": ["stock_landed_costs", "purchase_stock"],
"data": ["views/purchase_order_view.xml", "views/stock_landed_cost_view.xml"],
"installable": True,
"maintainers": ["victoralmau"],
}
50 changes: 50 additions & 0 deletions stock_landed_costs_purchase_auto/i18n/es.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_landed_costs_purchase_auto
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-12-23 15:39+0000\n"
"PO-Revision-Date: 2021-12-23 16:39+0100\n"
"Last-Translator: \n"
"Language-Team: \n"
"Language: es\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: \n"
"X-Generator: Poedit 2.3\n"

#. module: stock_landed_costs_purchase_auto
#: model:ir.model.fields,field_description:stock_landed_costs_purchase_auto.field_purchase_order__landed_cost_number
#, fuzzy
msgid "Landed Cost Number"
msgstr "Total de costes en destino"

#. module: stock_landed_costs_purchase_auto
#: model:ir.model.fields,field_description:stock_landed_costs_purchase_auto.field_purchase_order__landed_cost_ids
#: model_terms:ir.ui.view,arch_db:stock_landed_costs_purchase_auto.purchase_order_form
msgid "Landed Costs"
msgstr "Costes en destino"

#. module: stock_landed_costs_purchase_auto
#: model:ir.model.fields,field_description:stock_landed_costs_purchase_auto.field_stock_landed_cost__purchase_id
msgid "Purchase"
msgstr "Compra"

#. module: stock_landed_costs_purchase_auto
#: model:ir.model,name:stock_landed_costs_purchase_auto.model_purchase_order
msgid "Purchase Order"
msgstr "Pedido de compra"

#. module: stock_landed_costs_purchase_auto
#: model:ir.model,name:stock_landed_costs_purchase_auto.model_purchase_order_line
msgid "Purchase Order Line"
msgstr ""

#. module: stock_landed_costs_purchase_auto
#: model:ir.model,name:stock_landed_costs_purchase_auto.model_stock_landed_cost
msgid "Stock Landed Cost"
msgstr "Coste en destino"
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * stock_landed_costs_purchase_auto
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 13.0\n"
"Report-Msgid-Bugs-To: \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: stock_landed_costs_purchase_auto
#: model:ir.model.fields,field_description:stock_landed_costs_purchase_auto.field_purchase_order__landed_cost_number
msgid "Landed Cost Number"
msgstr ""

#. module: stock_landed_costs_purchase_auto
#: model:ir.model.fields,field_description:stock_landed_costs_purchase_auto.field_purchase_order__landed_cost_ids
#: model_terms:ir.ui.view,arch_db:stock_landed_costs_purchase_auto.purchase_order_form
msgid "Landed Costs"
msgstr ""

#. module: stock_landed_costs_purchase_auto
#: model:ir.model.fields,field_description:stock_landed_costs_purchase_auto.field_stock_landed_cost__purchase_id
msgid "Purchase"
msgstr ""

#. module: stock_landed_costs_purchase_auto
#: model:ir.model,name:stock_landed_costs_purchase_auto.model_purchase_order
msgid "Purchase Order"
msgstr ""

#. module: stock_landed_costs_purchase_auto
#: model:ir.model,name:stock_landed_costs_purchase_auto.model_purchase_order_line
msgid "Purchase Order Line"
msgstr ""

#. module: stock_landed_costs_purchase_auto
#: model:ir.model,name:stock_landed_costs_purchase_auto.model_stock_landed_cost
msgid "Stock Landed Cost"
msgstr ""
4 changes: 4 additions & 0 deletions stock_landed_costs_purchase_auto/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from . import purchase_order
from . import stock_landed_cost
71 changes: 71 additions & 0 deletions stock_landed_costs_purchase_auto/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Copyright 2021-2023 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import fields, models


class PurchaseOrder(models.Model):
_inherit = "purchase.order"

landed_cost_ids = fields.One2many(
comodel_name="stock.landed.cost",
inverse_name="purchase_id",
string="Landed Costs",
)
landed_cost_number = fields.Integer(compute="_compute_landed_cost_number")

def _compute_landed_cost_number(self):
domain = [("purchase_id", "in", self.ids)]
res = self.env["stock.landed.cost"].read_group(
domain=domain, fields=["purchase_id"], groupby=["purchase_id"]
)
landed_cost_dict = {x["purchase_id"][0]: x["purchase_id_count"] for x in res}
for item in self:
item.landed_cost_number = landed_cost_dict.get(item.id, 0)

def _prepare_landed_cost_values(self, picking):
return {
"purchase_id": self.id,
"picking_ids": [(4, picking.id)],
}

def _create_picking_with_stock_landed_cost(self, picking):
self.ensure_one()
landed_cost = (
self.env["stock.landed.cost"]
.with_company(self.company_id)
.create(self._prepare_landed_cost_values(picking))
)
self.write({"landed_cost_ids": [(4, landed_cost.id)]})

def _create_picking(self):
all_pickings = self.mapped("picking_ids")
res = super()._create_picking()
for order in self:
order_pickings = order.picking_ids - all_pickings
if order_pickings:
order._create_picking_with_stock_landed_cost(
fields.first(order_pickings)
)
return res

def action_view_stock_landed_cost(self):
action = self.env["ir.actions.act_window"]._for_xml_id(
"stock_landed_costs.action_stock_landed_cost"
)
action["context"] = {"search_default_purchase_id": self.id}
return action


class PurchaseOrderLine(models.Model):
_inherit = "purchase.order.line"

def _create_or_update_picking(self):
all_pickings = self.mapped("order_id.picking_ids")
res = super()._create_or_update_picking()
for order in self.mapped("order_id"):
order_pickings = order.picking_ids - all_pickings
if order_pickings:
order._create_picking_with_stock_landed_cost(
fields.first(order_pickings)
)
return res
10 changes: 10 additions & 0 deletions stock_landed_costs_purchase_auto/models/stock_landed_cost.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Copyright 2021 Tecnativa - Víctor Martínez
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import fields, models


class StockLandedCost(models.Model):
_inherit = "stock.landed.cost"

purchase_id = fields.Many2one(comodel_name="purchase.order", string="Purchase")
4 changes: 4 additions & 0 deletions stock_landed_costs_purchase_auto/readme/CONTRIBUTORS.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
* `Tecnativa <https://www.tecnativa.com>`_

* Pedro M. Baeza
* Víctor Martínez
2 changes: 2 additions & 0 deletions stock_landed_costs_purchase_auto/readme/DESCRIPTION.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This addon will auto-create a stock landed cost linked to the purchase order when it is
confirmed.
7 changes: 7 additions & 0 deletions stock_landed_costs_purchase_auto/readme/USAGE.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#. Go to Purchase> Orders > Requests for Quotation.
#. Create an order with any product.
#. Confirm Order.
#. Go to "Receipt" smart-button.
#. Validate picking.
#. Go to Inventory > Operations > Landed Costs.
#. There will be a record related to the purchase order and the validated picking.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading