Skip to content

Commit

Permalink
[IMP] purchase_stock_picking_invoice_link: black, isort, prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernesto Tejeda authored and JasminSForgeFlow committed Dec 17, 2024
1 parent 5c97597 commit ace98ec
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 71 deletions.
26 changes: 10 additions & 16 deletions purchase_stock_picking_invoice_link/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,14 @@
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

{
'name': 'Purchase Stock Picking Invoice Link',
'version': '12.0.1.0.0',
'category': 'Warehouse Management',
'summary': 'Adds link between purchases, pickings and invoices',
'author': 'Tecnativa, '
'Odoo Community Association (OCA)',
'website': 'http://github.com/OCA/stock-logistics-workflow',
'license': 'AGPL-3',
'depends': [
'stock_picking_invoice_link',
'purchase',
],
'data': [
'views/account_invoice_views.xml',
],
'installable': True,
"name": "Purchase Stock Picking Invoice Link",
"version": "12.0.1.0.0",
"category": "Warehouse Management",
"summary": "Adds link between purchases, pickings and invoices",
"author": "Tecnativa, " "Odoo Community Association (OCA)",
"website": "http://github.com/OCA/stock-logistics-workflow",
"license": "AGPL-3",
"depends": ["stock_picking_invoice_link", "purchase",],
"data": ["views/account_invoice_views.xml",],
"installable": True,
}
30 changes: 14 additions & 16 deletions purchase_stock_picking_invoice_link/models/account_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,34 @@ class AccountInvoice(models.Model):
@api.multi
def _prepare_invoice_line_from_po_line(self, line):
vals = super()._prepare_invoice_line_from_po_line(line)
moves = self.env['stock.move'].search([
('purchase_line_id', '=', line.id),
])
moves = self.env["stock.move"].search([("purchase_line_id", "=", line.id),])
if moves:
move_ids = moves._get_moves()
vals['move_line_ids'] = [(6, 0, move_ids.ids)]
pickings = move_ids.mapped('picking_id')
vals["move_line_ids"] = [(6, 0, move_ids.ids)]
pickings = move_ids.mapped("picking_id")
for picking in pickings:
picking.invoice_ids = [(4, self.id)]
return vals

@api.model
def create(self, vals_list):
pickings = self.env['stock.picking']
pickings = self.env["stock.picking"]
result = []
if 'invoice_line_ids' not in vals_list:
if "invoice_line_ids" not in vals_list:
return super().create(vals_list)
for item in vals_list.get('invoice_line_ids'):
if not item[2].get('purchase_line_id'):
for item in vals_list.get("invoice_line_ids"):
if not item[2].get("purchase_line_id"):
continue
moves = self.env['stock.move'].search([
('purchase_line_id', '=', item[2]['purchase_line_id']),
])
moves = self.env["stock.move"].search(
[("purchase_line_id", "=", item[2]["purchase_line_id"]),]
)
if moves:
move_ids = moves._get_moves()
item[2]['move_line_ids'] = [(6, 0, move_ids.ids)]
pickings |= move_ids.mapped('picking_id')
item[2]["move_line_ids"] = [(6, 0, move_ids.ids)]
pickings |= move_ids.mapped("picking_id")
result.append(item)
if result and vals_list.get('invoice_line_ids'):
vals_list['invoice_line_ids'] = result
if result and vals_list.get("invoice_line_ids"):
vals_list["invoice_line_ids"] = result
res = super().create(vals_list)
if res:
for picking in pickings:
Expand Down
13 changes: 7 additions & 6 deletions purchase_stock_picking_invoice_link/models/stock_move.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ class StockMove(models.Model):
@api.multi
def _get_moves(self):
return self.filtered(
lambda x: x.state == 'done' and
not x.scrapped and (
x.location_id.usage == 'supplier' or
(x.location_dest_id.usage == 'customer' and
x.to_refund)
))
lambda x: x.state == "done"
and not x.scrapped
and (
x.location_id.usage == "supplier"
or (x.location_dest_id.usage == "customer" and x.to_refund)
)
)
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
# Copyright 2019 Vicent Cubells <[email protected]>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html

from odoo.tests import common
from odoo import fields
from odoo.tests import common


class TestPurchaseSTockPickingInvoiceLink(common.SavepointCase):
@classmethod
def setUpClass(cls):
super(TestPurchaseSTockPickingInvoiceLink, cls).setUpClass()

cls.supplier = cls.env['res.partner'].create({
'name': 'Supplier for Test',
'supplier': True,
})
product = cls.env['product.product'].create({
'name': 'Product for Test',
})
cls.po = cls.env['purchase.order'].create({
'partner_id': cls.supplier.id,
'order_line': [(0, 0, {
'product_id': product.id,
'name': product.name,
'product_qty': 1.0,
'date_planned': fields.date.today(),
'product_uom': product.uom_po_id.id,
'price_unit': 15.0,
})]
})
cls.supplier = cls.env["res.partner"].create(
{"name": "Supplier for Test", "supplier": True,}
)
product = cls.env["product.product"].create({"name": "Product for Test",})
cls.po = cls.env["purchase.order"].create(
{
"partner_id": cls.supplier.id,
"order_line": [
(
0,
0,
{
"product_id": product.id,
"name": product.name,
"product_qty": 1.0,
"date_planned": fields.date.today(),
"product_uom": product.uom_po_id.id,
"price_unit": 15.0,
},
)
],
}
)

def test_puchase_stock_picking_invoice_link(self):
# Purchase order confirm
Expand All @@ -39,19 +44,21 @@ def test_puchase_stock_picking_invoice_link(self):
picking.move_lines.quantity_done = 1.0
picking.button_validate()
# Invoice purchase
self.invoice = self.env['account.invoice'].create({
'partner_id': self.supplier.id,
'purchase_id': self.po.id,
'account_id': self.supplier.property_account_payable_id.id,
'type': 'in_invoice',
})
self.invoice = self.env["account.invoice"].create(
{
"partner_id": self.supplier.id,
"purchase_id": self.po.id,
"account_id": self.supplier.property_account_payable_id.id,
"type": "in_invoice",
}
)
self.invoice.purchase_order_change()
self.invoice.action_invoice_open()
# Only one invoice line has been created
self.assertEqual(len(self.invoice.invoice_line_ids), 1)
line = self.invoice.invoice_line_ids
# Move lines are set in invoice lines
self.assertEqual(len(line.mapped('move_line_ids')), 1)
self.assertEqual(line.mapped('move_line_ids'), picking.move_lines)
self.assertEqual(len(line.mapped("move_line_ids")), 1)
self.assertEqual(line.mapped("move_line_ids"), picking.move_lines)
# Invoices are set in pickings
self.assertEqual(picking.invoice_ids, self.invoice)
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<record id="invoice_supplier_form" model="ir.ui.view">
<field name="name">account.invoice.supplier.form</field>
<field name="model">account.invoice</field>
<field name="inherit_id" ref="account.invoice_supplier_form"/>
<field name="inherit_id" ref="account.invoice_supplier_form" />
<field name="arch" type="xml">
<notebook position="inside">
<page string="Pickings" name="pickings" attrs="{'invisible': [('picking_ids', '=', [])]}">
<field name="picking_ids"/>
<page
string="Pickings"
name="pickings"
attrs="{'invisible': [('picking_ids', '=', [])]}"
>
<field name="picking_ids" />
</page>
</notebook>
</field>
</record>

</odoo>

0 comments on commit ace98ec

Please sign in to comment.