Skip to content

Commit

Permalink
[IMP] Picking invoicing fields and functions merged from stock_pickin…
Browse files Browse the repository at this point in the history
…g_invoicing
  • Loading branch information
yibudak committed Mar 6, 2025
1 parent 125d467 commit ee5e2d6
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 3 deletions.
1 change: 1 addition & 0 deletions altinkaya_account/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"sale",
"stock",
"sale_stock",
"purchase",
"delivery",
"base_partner_sequence",
],
Expand Down
71 changes: 68 additions & 3 deletions altinkaya_account/models/account_move.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
# Copyright 2025 Ismail Çağan Yılmaz (https://github.com/milleniumkid)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models, _
from odoo import _, fields, models
from odoo.exceptions import ValidationError


class AccountMove(models.Model):
Expand All @@ -12,7 +13,10 @@ class AccountMove(models.Model):
x_comment_export = fields.Text("ihracat fatura notu")
z_tevkifatli_mi = fields.Boolean(
"Tevkifatlı",
help="Eger fatura tevkifatli fatura ise bu alan secilmeli Sadece zirve programi transferinde kullanilmaktadir.",
help=(
"Eger fatura tevkifatli fatura ise bu alan secilmeli "
"Sadece zirve programi transferinde kullanilmaktadir."
),
)
carrier_id = fields.Many2one("delivery.carrier", "Carrier")
x_serino = fields.Char("Fatura No", size=64)
Expand All @@ -32,6 +36,12 @@ class AccountMove(models.Model):
compute="_compute_waiting_picking_ids",
)

delivery_ref_no = fields.Char(
string="Delivery Reference No.",
help="Delivery carrier reference number before"
" the shipment is sent to the carrier.",
)

def _compute_partner_balance(self):
for move in self:
partner = move.partner_id
Expand All @@ -53,6 +63,15 @@ def _compute_waiting_picking_ids(self):

return stocks

def _onchange_invoice_line_ids(self):
"""This method was removed in 16.0 but we've added a simulation of it here"""
for invoice in self:
invoice._onchange_partner_id()
invoice._onchange_date()
invoice._compute_currency_id()
invoice._compute_tax_totals()
invoice._compute_amount()

def action_post(self):
res = super().action_post()
user = self.env.user
Expand All @@ -76,7 +95,7 @@ def action_post(self):
move._compute_currency_change_rate()
move.action_account_change_currency()

move._onchange_quick_edit_line_ids() # Recompute taxes
move._onchange_invoice_line_ids() # Recompute taxes
if (
move.move_type == "in_invoice"
and fields.first(move.invoice_line_ids).account_id
Expand All @@ -90,3 +109,49 @@ def action_post(self):
)

return res

def action_match_einvoice_lines_picking(self):
"""
Match invoice lines with picking lines
:return: bool
"""
for invoice in self:
if not invoice.picking_ids:
raise ValidationError(_("No picking linked to this invoice"))
old_invoice_lines = invoice.invoice_line_ids.filtered(
lambda line: not (
line.name_xml
or line.SellersItemIdentification
or line.ManufacturersItemIdentification
or line.description
)
)
old_invoice_lines.unlink()
for picking in invoice.picking_ids:
moves = picking.mapped("move_lines")
for move in moves:
partner_order_ref = move._get_partner_order_ref()
move_picking_ref = move._get_picking_ref()
invoice_line = invoice.invoice_line_ids.filtered(
lambda l: l.product_id == move.product_id
)
purchase_line = move.purchase_line_id
# Link Invoice Lines with Move and Purchase Line
invoice_line.write(
{
"purchase_id": picking.purchase_id.id,
"purchase_line_id": purchase_line.id,
"move_line_ids": [(6, 0, move.move_line_ids.ids)],
"partner_order_ref": partner_order_ref,
"moves_picking_ref": move_picking_ref,
}
)
# Link Move with Invoice Lines
move.write(
{
"invoice_line_ids": [(6, 0, invoice_line.ids)],
}
)
invoice._compute_tax_totals()
invoice._create_missing_supplierinfo()
return True
25 changes: 25 additions & 0 deletions altinkaya_account/models/account_move_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,28 @@ class AccountMoveLine(models.Model):

move_name = fields.Char(related="move_id.name", string="Move Number")
move_ref = fields.Char(related="move_id.ref", string="Move Reference")
lot_ids = fields.Many2many(
"stock.lot",
relation="account_move_line_stock_lot_rel",
column1="move_line_id",
column2="lot_id",
string="Lots/Serial Numbers",
)
moves_picking_ref = fields.Char(string="Picking Ref")
partner_order_ref = fields.Char(string="Order Reference")
purchase_line_amount = fields.Float(
string="PO Unit", related="purchase_line_id.price_unit"
)


def _simulate_invoice_line_onchange(self):
"""
Simulate onchange for invoice line
:param values: dict
:return: dict
"""
for line in self:
line._inverse_partner_id()
line._inverse_product_id()
line._inverse_account_id()
line._inverse_amount_currency()
23 changes: 23 additions & 0 deletions altinkaya_account/views/account_move_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,29 @@
</field>
</page>
</xpath>

<xpath expr="//group[@name='sale_info_group']/field[@name='ref']" position="after">
<field name="delivery_ref_no" />
</xpath>

<xpath expr="//field[@name='invoice_line_ids']/tree" position="inside">
<field name="move_type" invisible="1" />
<field name="purchase_line_amount" attrs="{'invisible': [('move_type','not in',['in_invoice', 'in_refund'])]}" />
<field name="partner_order_ref"/>
<field name="moves_picking_ref"/>
<field name="lot_ids" widget="many2many_tags"/>
</xpath>

<xpath expr="//button[@name='button_cancel']"
position="after">
<button name="action_match_einvoice_lines_picking" type="object"
class="oe_highlight"
string="Match Picking Lines"
attrs="{'invisible':['|', ('move_type', 'not in', ['in_invoice', 'in_refund']), '&amp;', '&amp;', ('picking_ids', '=', False), ('invoice_line_ids', '=', False), ('state', 'in', ['done', 'cancel'])]}"
groups="account.group_account_invoice"/>

</xpath>

</field>
</record>
</odoo>

0 comments on commit ee5e2d6

Please sign in to comment.