Skip to content

Commit

Permalink
[REF] stock_picking_invoicing: Removed unnecessary fields at the crea…
Browse files Browse the repository at this point in the history
…tion of Invoice and check if those fields are being filled.
  • Loading branch information
mbcosta committed May 10, 2023
1 parent 62bcc20 commit d8cf1b9
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
8 changes: 8 additions & 0 deletions stock_picking_invoicing/demo/stock_picking_demo.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo>

<!-- Fiscal Position -->
<record id="fiscal_position_demo" model="account.fiscal.position">
<field name="name">Test - Stock Picking Invocing</field>
<field name="company_id" ref="base.main_company" />
<field name="auto_apply">1</field>
</record>

<!-- Customer -->
<!-- Stocking Picking - To be Invoiced - State Draft-->
<record id="stock_picking_invoicing_1" model="stock.picking">
Expand Down
8 changes: 7 additions & 1 deletion stock_picking_invoicing/tests/test_picking_invoicing.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,21 @@ def test_0_picking_out_invoicing(self):
self.assertIn(picking, invoice.picking_ids)
nb_invoice_after = self.invoice_model.search_count([])
self.assertEqual(nb_invoice_before, nb_invoice_after - len(invoice))
assert invoice.invoice_user_id, "Error to map User in Invoice."
assert invoice.invoice_payment_term_id, "Error to map Payment Term in Invoice."
assert invoice.fiscal_position_id, "Error to map Fiscal Position in Invoice."
assert invoice.company_id, "Error to map Company in Invoice."
assert invoice.invoice_line_ids, "Error to create invoice line."
for inv_line in invoice.invoice_line_ids:
assert inv_line.account_id, "Error to map Account in Invoice Line."
assert inv_line.tax_ids, "Error to map Sale Tax in Invoice Line."
assert inv_line.product_uom_id, "Error to map Product UOM in Invoice Line."
for mv_line in inv_line.move_line_ids:
self.assertEqual(
mv_line.id,
new_move.id,
"Error to link stock.move with invoice.line.",
)
self.assertTrue(inv_line.tax_ids, "Error to map Sale Tax in invoice.line.")

def test_1_picking_out_invoicing(self):
nb_invoice_before = self.invoice_model.search_count([])
Expand Down
28 changes: 1 addition & 27 deletions stock_picking_invoicing/wizards/stock_invoice_onshipping.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,12 +353,7 @@ def _build_invoice_values_from_pickings(self, pickings):
partner_id = picking._get_partner_to_invoice()
partner = self.env["res.partner"].browse(partner_id)
inv_type = self._get_invoice_type()
if inv_type in ("out_invoice", "out_refund"):
payment_term = partner.property_payment_term_id.id
else:
payment_term = partner.property_supplier_payment_term_id.id
company = self.env.company
currency = company.currency_id
currency = self.env.company.currency_id
if partner:
code = picking.picking_type_id.code
if partner.property_product_pricelist and code == "outgoing":
Expand All @@ -369,12 +364,8 @@ def _build_invoice_values_from_pickings(self, pickings):
values.update(
{
"invoice_origin": ", ".join(pickings.mapped("name")),
"user_id": self.env.user.id,
"partner_id": partner_id,
"invoice_payment_term_id": payment_term,
"move_type": inv_type,
"fiscal_position_id": partner.property_account_position_id.id,
"company_id": company.id,
"currency_id": currency.id,
"journal_id": journal.id,
"picking_ids": [(4, p.id, False) for p in pickings],
Expand Down Expand Up @@ -435,21 +426,8 @@ def _get_invoice_line_values(self, moves, invoice_values, invoice):
name = ", ".join(moves.mapped("name"))
move = fields.first(moves)
product = move.product_id
fiscal_position = self.env["account.fiscal.position"].browse(
invoice_values["fiscal_position_id"]
)
partner_id = self.env["res.partner"].browse(invoice_values["partner_id"])
categ = product.categ_id
inv_type = invoice_values["move_type"]
if inv_type in ("out_invoice", "out_refund"):
account = product.property_account_income_id
if not account:
account = categ.property_account_income_categ_id
else:
account = product.property_account_expense_id
if not account:
account = categ.property_account_expense_categ_id
account = move._get_account(fiscal_position, account)
quantity = 0
move_line_ids = []
for move in moves:
Expand All @@ -467,19 +445,15 @@ def _get_invoice_line_values(self, moves, invoice_values, invoice):
qty *= -1
quantity += qty
move_line_ids.append((4, move.id, False))
taxes = moves._get_taxes(fiscal_position, inv_type)
price = moves._get_price_unit_invoice(inv_type, partner_id, quantity)
line_obj = self.env["account.move.line"]
values = line_obj.default_get(line_obj.fields_get().keys())
values.update(
{
"name": name,
"account_id": account.id,
"product_id": product.id,
"product_uom_id": product.uom_id.id,
"quantity": quantity,
"price_unit": price,
"tax_ids": [(6, 0, taxes.ids)],
"move_line_ids": move_line_ids,
"move_id": invoice.id,
}
Expand Down

0 comments on commit d8cf1b9

Please sign in to comment.