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

[3438][3894][IMP] account_move_obc_csv #55

Merged
merged 6 commits into from
Oct 27, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 2 additions & 1 deletion account_move_obc_csv/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
"name": "Account Move OBC CSV",
"version": "16.0.1.0.0",
"version": "16.0.1.0.1",
"category": "Accounting",
"author": "Quartile Limited",
"website": "https://www.quartile.co",
"license": "AGPL-3",
"depends": [
"account",
"mrp_subcontracting",
"report_csv",
],
"data": [
Expand Down
35 changes: 32 additions & 3 deletions account_move_obc_csv/report/report_account_move_obc_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import csv
from collections import defaultdict

from odoo import _, models
from odoo import _, api, models
from odoo.exceptions import UserError


Expand All @@ -14,6 +14,7 @@ class AccountMoveObcCsv(models.AbstractModel):

def _get_fields(self):
return [
"GL0010000", # asterisk
"GL0010001", # date
"GL0012002", # debit account
"GL0012101", # debit base amount
Expand Down Expand Up @@ -75,6 +76,15 @@ def _check_records(self, records):
% ("\n".join(exported_records.mapped("name")))
)

@api.model
def _get_partner(self, line):
if line.partner_id:
return line.partner_id
# Try identifying the subcontracted partner from the production order.
stock_move = line.move_id.stock_move_id
production = stock_move.production_id or stock_move.raw_material_production_id
return production.subcontractor_id

def _update_vals(self, vals, line, move_analytic_accounts, drcr):
account_code = line.account_id.code
subaccount_code = ""
Expand Down Expand Up @@ -118,6 +128,7 @@ def _update_vals(self, vals, line, move_analytic_accounts, drcr):
!= line.product_id.categ_id.property_stock_account_input_categ_id
):
tax = line.tax_ids[:1]
partner = self._get_partner(line)
fields = self._get_field_map()
vals[fields["account"][drcr]] = account_code
vals[fields["base_amount"][drcr]] = line.debit if drcr == "dr" else line.credit
Expand All @@ -130,7 +141,7 @@ def _update_vals(self, vals, line, move_analytic_accounts, drcr):
)
vals[fields["tax_rate"][drcr]] = tax.amount or 0
vals[fields["tax_auto_calc"][drcr]] = 0 # No tax calculation
vals[fields["partner"][drcr]] = line.partner_id.ref or ""
vals[fields["partner"][drcr]] = partner.ref or ""
vals[fields["project"][drcr]] = project.code or ""
return vals

Expand Down Expand Up @@ -177,9 +188,27 @@ def _get_report_vals_dict(self, record):

def generate_csv_report(self, writer, data, records):
self._check_records(records)
# Sort records by date and then by picking_id
sorted_records = sorted(
records, key=lambda r: (r.date, r.stock_move_id.picking_id.id)
)
writer.writeheader()
for record in records:
picking = self.env["stock.picking"]
for record in sorted_records:
vals_dict = self._get_report_vals_dict(record)
# Assign a demarkation symbol ('*') to the first journal entry of a picking
# to consolidate the entries into one record in the OBC system. This is to
# ease the operation of attaching the proof documents to the entries in the
# system.
first_record = False
record_picking = record.stock_move_id.picking_id
if not record_picking:
first_record = True
elif picking != record_picking:
first_record = True
picking = record_picking
if first_record:
vals_dict[1]["GL0010000"] = "*"
for _k, v in sorted(vals_dict.items()):
writer.writerow(v)
record.is_exported = True
Expand Down
Loading