Skip to content

Commit

Permalink
[14.0][ADD] purchase_create_requisition_usability: When creating a re…
Browse files Browse the repository at this point in the history
…quisition, take purchase lines to thee requisition.
  • Loading branch information
Berezi authored and anajuaristi committed Dec 4, 2024
1 parent 3286dc3 commit 44f6dca
Show file tree
Hide file tree
Showing 11 changed files with 285 additions and 0 deletions.
28 changes: 28 additions & 0 deletions purchase_create_requisition_usability/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
.. 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

=====================================
Purchase Create Requisition Usability
=====================================

When creating an requistion from purchase order, generates the purchase order lines in the requisition.

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.

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

Credits
=======

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

* Berezi Amubieta <bereziamubieta@avanzosc.es>
* Ana Juaristi <anajuaristi@avanzosc.es>
1 change: 1 addition & 0 deletions purchase_create_requisition_usability/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions purchase_create_requisition_usability/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Copyright 2024 Berezi Amubieta - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
{
"name": "Purchase Create Requisition Usability",
"version": "14.0.1.0.0",
"author": "Avanzosc",
"category": "Inventory",
"website": "https://github.com/avanzosc/odoo-addons",
"depends": [
"purchase_requisition",
],
"data": [
"views/purchase_order_view.xml",
],
"license": "AGPL-3",
"installable": True,
}
45 changes: 45 additions & 0 deletions purchase_create_requisition_usability/i18n/es.po
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:
# * purchase_create_requisition_usability
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-12-03 09:45+0000\n"
"PO-Revision-Date: 2024-12-03 09:45+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: purchase_create_requisition_usability
#: model:ir.model.fields,field_description:purchase_create_requisition_usability.field_purchase_order__display_name
#: model:ir.model.fields,field_description:purchase_create_requisition_usability.field_purchase_requisition__display_name
msgid "Display Name"
msgstr "Nombre mostrado"

#. module: purchase_create_requisition_usability
#: model:ir.model.fields,field_description:purchase_create_requisition_usability.field_purchase_order__id
#: model:ir.model.fields,field_description:purchase_create_requisition_usability.field_purchase_requisition__id
msgid "ID"
msgstr ""

#. module: purchase_create_requisition_usability
#: model:ir.model.fields,field_description:purchase_create_requisition_usability.field_purchase_order____last_update
#: model:ir.model.fields,field_description:purchase_create_requisition_usability.field_purchase_requisition____last_update
msgid "Last Modified on"
msgstr "Última modificación el"

#. module: purchase_create_requisition_usability
#: model:ir.model,name:purchase_create_requisition_usability.model_purchase_order
#: model:ir.model.fields,field_description:purchase_create_requisition_usability.field_purchase_requisition__purchase_order_ids
msgid "Purchase Order"
msgstr "Pedido de compra"

#. module: purchase_create_requisition_usability
#: model:ir.model,name:purchase_create_requisition_usability.model_purchase_requisition
msgid "Purchase Requisition"
msgstr "Solicitud de compra"
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:
# * purchase_create_requisition_usability
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0+e\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2024-12-03 09:44+0000\n"
"PO-Revision-Date: 2024-12-03 09:44+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: purchase_create_requisition_usability
#: model:ir.model.fields,field_description:purchase_create_requisition_usability.field_purchase_order__display_name
#: model:ir.model.fields,field_description:purchase_create_requisition_usability.field_purchase_requisition__display_name
msgid "Display Name"
msgstr ""

#. module: purchase_create_requisition_usability
#: model:ir.model.fields,field_description:purchase_create_requisition_usability.field_purchase_order__id
#: model:ir.model.fields,field_description:purchase_create_requisition_usability.field_purchase_requisition__id
msgid "ID"
msgstr ""

#. module: purchase_create_requisition_usability
#: model:ir.model.fields,field_description:purchase_create_requisition_usability.field_purchase_order____last_update
#: model:ir.model.fields,field_description:purchase_create_requisition_usability.field_purchase_requisition____last_update
msgid "Last Modified on"
msgstr ""

#. module: purchase_create_requisition_usability
#: model:ir.model,name:purchase_create_requisition_usability.model_purchase_order
#: model:ir.model.fields,field_description:purchase_create_requisition_usability.field_purchase_requisition__purchase_order_ids
msgid "Purchase Order"
msgstr ""

#. module: purchase_create_requisition_usability
#: model:ir.model,name:purchase_create_requisition_usability.model_purchase_requisition
msgid "Purchase Requisition"
msgstr ""
2 changes: 2 additions & 0 deletions purchase_create_requisition_usability/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import purchase_requisition
from . import purchase_order
83 changes: 83 additions & 0 deletions purchase_create_requisition_usability/models/purchase_order.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Copyright 2024 Berezi Amubieta - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models


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

@api.onchange("requisition_id")
def _onchange_requisition_id(self):
if self.requisition_id:
self = self.with_company(self.company_id)
requisition = self.requisition_id
if self.partner_id:
partner = self.partner_id
else:
partner = requisition.vendor_id
payment_term = partner.property_supplier_payment_term_id
FiscalPosition = self.env["account.fiscal.position"]
fpos = FiscalPosition.with_company(self.company_id).get_fiscal_position(
partner.id
)
self.partner_id = partner.id
self.fiscal_position_id = fpos.id
self.payment_term_id = (payment_term.id,)
self.company_id = requisition.company_id.id
self.currency_id = requisition.currency_id.id
if not self.origin or requisition.name not in self.origin.split(", "):
if self.origin:
if requisition.name:
self.origin = self.origin + ", " + requisition.name
else:
self.origin = requisition.name
self.notes = requisition.description
self.date_order = fields.Datetime.now()
if requisition.type_id.line_copy != "copy":
return
order_lines = []
for line in requisition.line_ids:
product_lang = line.product_id.with_context(
lang=partner.lang or self.env.user.lang, partner_id=partner.id
)
name = product_lang.display_name
if product_lang.description_purchase:
name += "\n" + product_lang.description_purchase
taxes_ids = fpos.map_tax(
line.product_id.supplier_taxes_id.filtered(
lambda tax: tax.company_id == requisition.company_id
)
).ids
if line.product_uom_id != line.product_id.uom_po_id:
product_qty = line.product_uom_id._compute_quantity(
line.product_qty, line.product_id.uom_po_id
)
price_unit = line.product_uom_id._compute_price(
line.price_unit, line.product_id.uom_po_id
)
else:
product_qty = line.product_qty
price_unit = line.price_unit
if requisition.type_id.quantity_copy != "copy":
product_qty = 0
order_line_values = line._prepare_purchase_order_line(
name=name,
product_qty=product_qty,
price_unit=price_unit,
taxes_ids=taxes_ids,
)
product = date_planned = False
if "product_id" in order_line_values:
product = self.env["product.product"].browse(
order_line_values.get("product_id")
)
if "date_planned" in order_line_values:
date_planned = order_line_values.get("date_planned").date()
if product and date_planned:
if self.order_line and self.order_line.filtered(
lambda c: c.product_id == product
):
continue
else:
order_lines.append((0, 0, order_line_values))
self.order_line = order_lines
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright 2024 Berezi Amubieta - AvanzOSC
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models


class PurchaseRequisition(models.Model):
_inherit = "purchase.requisition"

purchase_order_ids = fields.One2many(
comodel_name="purchase.order", inverse_name="requisition_id"
)

@api.model
def create(self, values):
result = super(PurchaseRequisition, self).create(values)
if "default_purchase_order_ids" in self.env.context:
purchases = self.env["purchase.order"].browse(
self.env.context["default_purchase_order_ids"]
)
for purchase in purchases:
for line in purchase.order_line:
prl_obj = self.env["purchase.requisition.line"]
new_prl = prl_obj.new(
{
"product_id": line.product_id.id,
"price_unit": line.price_unit,
"requisition_id": result.id,
"schedule_date": line.date_planned,
}
)
for onchange_method in new_prl._onchange_methods["product_id"]:
onchange_method(new_prl)
vals = new_prl._convert_to_write(new_prl._cache)
vals.update(
{
"product_qty": line.product_qty,
}
)
prl_obj.create(vals)
return result
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>
<record id="purchase_order_form" model="ir.ui.view">
<field name="model">purchase.order</field>
<field name="inherit_id" ref="purchase.purchase_order_form" />
<field name="arch" type="xml">
<field name="requisition_id" position="attributes">
<attribute
name="context"
>{'default_purchase_order_ids': [active_id]}</attribute>
<attribute
name="domain"
>[('state', 'not in', ('cancel', 'done')), ('vendor_id', 'in', (partner_id, False)), ('company_id', '=', company_id)]</attribute>
</field>
</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions setup/purchase_create_requisition_usability/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,
)

0 comments on commit 44f6dca

Please sign in to comment.