perubahan di customer ref dan perhitungan ongkir
This commit is contained in:
@@ -18,9 +18,9 @@ class SaleOrder(models.Model):
|
||||
copy=False,
|
||||
tracking=True,
|
||||
)
|
||||
customer_qr_ref = fields.Char(
|
||||
customer_ref = fields.Char(
|
||||
string="Referensi Customer",
|
||||
related="partner_id.commercial_partner_id.customer_qr_ref",
|
||||
related="partner_id.commercial_partner_id.ref",
|
||||
store=True,
|
||||
readonly=True,
|
||||
)
|
||||
|
||||
@@ -67,7 +67,7 @@
|
||||
<xpath expr="//field[@name='user_id']" position="after">
|
||||
<field name="business_category_id"/>
|
||||
<field name="customer_wilayah_kecamatan_id"/>
|
||||
<field name="customer_qr_ref"/>
|
||||
<field name="customer_ref"/>
|
||||
</xpath>
|
||||
<xpath expr="//filter[@name='salesperson']" position="after">
|
||||
<filter string="Business Category" name="group_by_business_category" context="{'group_by': 'business_category_id'}"/>
|
||||
@@ -87,7 +87,7 @@
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//field[@name='partner_id']" position="after">
|
||||
<field name="customer_wilayah_kecamatan_id" optional="show"/>
|
||||
<field name="customer_qr_ref" optional="show"/>
|
||||
<field name="customer_ref" optional="show"/>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
-- Expense destructive cleanup for production database `erp`
|
||||
-- Prepared on 2026-04-09
|
||||
-- Scope:
|
||||
-- hr.expense ids: 1, 2, 3, 4
|
||||
-- hr.expense.sheet id: 1
|
||||
-- account.move ids: 342, 343
|
||||
-- Mode:
|
||||
-- full cleanup for the four Riska Amalia expenses shown on 2026-04-04
|
||||
--
|
||||
-- WARNING:
|
||||
-- - This is destructive.
|
||||
-- - Execute only after full backup.
|
||||
-- - Run in a maintenance window.
|
||||
-- - This script removes both draft and done expenses in the selected batch.
|
||||
-- - This script also removes the related journal entry and its reversal.
|
||||
|
||||
BEGIN;
|
||||
|
||||
CREATE TEMP TABLE target_expenses (id integer PRIMARY KEY);
|
||||
INSERT INTO target_expenses (id) VALUES (1), (2), (3), (4);
|
||||
|
||||
CREATE TEMP TABLE target_sheets (id integer PRIMARY KEY);
|
||||
INSERT INTO target_sheets (id) VALUES (1);
|
||||
|
||||
CREATE TEMP TABLE target_moves (id integer PRIMARY KEY);
|
||||
INSERT INTO target_moves (id) VALUES (342), (343);
|
||||
|
||||
CREATE TEMP TABLE target_move_lines AS
|
||||
SELECT aml.id
|
||||
FROM account_move_line aml
|
||||
WHERE aml.move_id IN (SELECT id FROM target_moves);
|
||||
|
||||
CREATE INDEX target_move_lines_id_idx ON target_move_lines (id);
|
||||
|
||||
CREATE TEMP TABLE target_partial_reconcile AS
|
||||
SELECT apr.id
|
||||
FROM account_partial_reconcile apr
|
||||
WHERE
|
||||
apr.debit_move_id IN (SELECT id FROM target_move_lines)
|
||||
OR apr.credit_move_id IN (SELECT id FROM target_move_lines);
|
||||
|
||||
CREATE INDEX target_partial_reconcile_id_idx ON target_partial_reconcile (id);
|
||||
|
||||
CREATE TEMP TABLE target_analytic_lines AS
|
||||
SELECT aal.id
|
||||
FROM account_analytic_line aal
|
||||
WHERE aal.move_id IN (SELECT id FROM target_moves);
|
||||
|
||||
CREATE INDEX target_analytic_lines_id_idx ON target_analytic_lines (id);
|
||||
|
||||
-- Preview counts first
|
||||
SELECT 'target_expenses' AS label, COUNT(*) AS total FROM target_expenses;
|
||||
SELECT 'target_sheets' AS label, COUNT(*) AS total FROM target_sheets;
|
||||
SELECT 'target_moves' AS label, COUNT(*) AS total FROM target_moves;
|
||||
SELECT 'target_move_lines' AS label, COUNT(*) AS total FROM target_move_lines;
|
||||
SELECT 'target_partial_reconcile' AS label, COUNT(*) AS total FROM target_partial_reconcile;
|
||||
SELECT 'target_analytic_lines' AS label, COUNT(*) AS total FROM target_analytic_lines;
|
||||
|
||||
-- Expected at preparation time:
|
||||
-- target_expenses = 4
|
||||
-- target_sheets = 1
|
||||
-- target_moves = 2
|
||||
-- target_move_lines = 8
|
||||
-- target_partial_reconcile = 2
|
||||
-- target_analytic_lines = 0
|
||||
-- Verify again at execution time.
|
||||
|
||||
DELETE FROM account_partial_reconcile
|
||||
WHERE id IN (SELECT id FROM target_partial_reconcile);
|
||||
|
||||
DELETE FROM account_analytic_tag_account_move_line_rel
|
||||
WHERE account_move_line_id IN (SELECT id FROM target_move_lines);
|
||||
|
||||
DELETE FROM account_move_line_account_tax_rel
|
||||
WHERE account_move_line_id IN (SELECT id FROM target_move_lines);
|
||||
|
||||
DELETE FROM account_analytic_line
|
||||
WHERE id IN (SELECT id FROM target_analytic_lines);
|
||||
|
||||
DELETE FROM account_move_line
|
||||
WHERE id IN (SELECT id FROM target_move_lines);
|
||||
|
||||
UPDATE hr_expense_sheet
|
||||
SET account_move_id = NULL
|
||||
WHERE id IN (SELECT id FROM target_sheets);
|
||||
|
||||
UPDATE account_move
|
||||
SET reversed_entry_id = NULL
|
||||
WHERE id IN (SELECT id FROM target_moves);
|
||||
|
||||
DELETE FROM account_move
|
||||
WHERE id IN (SELECT id FROM target_moves);
|
||||
|
||||
DELETE FROM hr_expense
|
||||
WHERE id IN (SELECT id FROM target_expenses);
|
||||
|
||||
DELETE FROM hr_expense_sheet
|
||||
WHERE id IN (SELECT id FROM target_sheets);
|
||||
|
||||
SELECT 'remaining_expenses' AS label, COUNT(*) AS total
|
||||
FROM hr_expense
|
||||
WHERE id IN (1, 2, 3, 4);
|
||||
|
||||
SELECT 'remaining_sheets' AS label, COUNT(*) AS total
|
||||
FROM hr_expense_sheet
|
||||
WHERE id IN (1);
|
||||
|
||||
SELECT 'remaining_moves' AS label, COUNT(*) AS total
|
||||
FROM account_move
|
||||
WHERE id IN (342, 343);
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,71 @@
|
||||
-- Reset current stock quant for production database `erp`
|
||||
-- Prepared on 2026-04-09
|
||||
-- Scope:
|
||||
-- stock.location id: 8
|
||||
-- location name: WH/Stock
|
||||
-- Mode:
|
||||
-- destructive current on hand reset after inventory 22 cleanup
|
||||
--
|
||||
-- WARNING:
|
||||
-- - This script deletes stock.quant rows in the target location.
|
||||
-- - Execute only after full backup.
|
||||
-- - Run only after inventory/source cleanup is complete.
|
||||
-- - This script is for current on hand reset, not accounting history cleanup.
|
||||
|
||||
BEGIN;
|
||||
|
||||
CREATE TEMP TABLE target_locations (id integer PRIMARY KEY);
|
||||
INSERT INTO target_locations (id) VALUES (8);
|
||||
|
||||
CREATE TEMP TABLE target_quants AS
|
||||
SELECT sq.id
|
||||
FROM stock_quant sq
|
||||
JOIN stock_location sl ON sl.id = sq.location_id
|
||||
WHERE
|
||||
sq.location_id IN (SELECT id FROM target_locations)
|
||||
AND sl.usage IN ('internal', 'transit')
|
||||
AND COALESCE(sq.quantity, 0) <> 0;
|
||||
|
||||
CREATE INDEX target_quants_id_idx ON target_quants (id);
|
||||
|
||||
-- Preview counts
|
||||
SELECT 'target_locations' AS label, COUNT(*) AS total FROM target_locations;
|
||||
|
||||
SELECT 'target_quants' AS label, COUNT(*) AS total
|
||||
FROM target_quants;
|
||||
|
||||
SELECT 'target_quantity_sum' AS label, COALESCE(SUM(sq.quantity), 0) AS total
|
||||
FROM stock_quant sq
|
||||
WHERE sq.id IN (SELECT id FROM target_quants);
|
||||
|
||||
SELECT 'reserved_quants_in_scope' AS label, COUNT(*) AS total
|
||||
FROM stock_quant sq
|
||||
WHERE
|
||||
sq.location_id IN (SELECT id FROM target_locations)
|
||||
AND COALESCE(sq.reserved_quantity, 0) <> 0;
|
||||
|
||||
DO $$
|
||||
BEGIN
|
||||
IF EXISTS (
|
||||
SELECT 1
|
||||
FROM stock_quant sq
|
||||
WHERE
|
||||
sq.location_id IN (SELECT id FROM target_locations)
|
||||
AND COALESCE(sq.reserved_quantity, 0) <> 0
|
||||
) THEN
|
||||
RAISE EXCEPTION 'Abort reset_stock_quant_after_inventory22: reserved_quantity still exists in target scope.';
|
||||
END IF;
|
||||
END $$;
|
||||
|
||||
DELETE FROM stock_quant
|
||||
WHERE id IN (SELECT id FROM target_quants);
|
||||
|
||||
SELECT 'remaining_quants_nonzero' AS label, COUNT(*) AS total
|
||||
FROM stock_quant sq
|
||||
JOIN stock_location sl ON sl.id = sq.location_id
|
||||
WHERE
|
||||
sq.location_id IN (SELECT id FROM target_locations)
|
||||
AND sl.usage IN ('internal', 'transit')
|
||||
AND COALESCE(sq.quantity, 0) <> 0;
|
||||
|
||||
COMMIT;
|
||||
@@ -0,0 +1,155 @@
|
||||
-- STJ destructive cleanup for production database `erp`
|
||||
-- Prepared on 2026-04-09
|
||||
-- Scope:
|
||||
-- stock.inventory id: 22
|
||||
-- inventory name: Stok Persediaan
|
||||
-- plus manual STJ entries created after inventory posting for products in this batch
|
||||
-- Mode:
|
||||
-- full source cleanup + manual STJ cleanup for current inventory batch
|
||||
--
|
||||
-- WARNING:
|
||||
-- - This is destructive.
|
||||
-- - Execute only after full backup.
|
||||
-- - Run in a maintenance window.
|
||||
-- - This script removes:
|
||||
-- 1. journal code STJ linked to stock moves from inventory 22
|
||||
-- 2. manual journal code STJ with stock_move_id IS NULL whose `ref` matches
|
||||
-- product default_code from inventory 22
|
||||
-- 3. stock/source history for inventory 22
|
||||
-- - This script does NOT reset stock.quant. Run the stock quant reset script after this cleanup if needed.
|
||||
|
||||
BEGIN;
|
||||
|
||||
CREATE TEMP TABLE target_inventories (id integer PRIMARY KEY);
|
||||
INSERT INTO target_inventories (id) VALUES (22);
|
||||
|
||||
CREATE TEMP TABLE target_stock_moves AS
|
||||
SELECT sm.id
|
||||
FROM stock_move sm
|
||||
WHERE sm.inventory_id IN (SELECT id FROM target_inventories);
|
||||
|
||||
CREATE INDEX target_stock_moves_id_idx ON target_stock_moves (id);
|
||||
|
||||
CREATE TEMP TABLE target_manual_refs AS
|
||||
SELECT DISTINCT pp.default_code AS ref
|
||||
FROM stock_move sm
|
||||
JOIN product_product pp ON pp.id = sm.product_id
|
||||
WHERE
|
||||
sm.id IN (SELECT id FROM target_stock_moves)
|
||||
AND COALESCE(pp.default_code, '') <> '';
|
||||
|
||||
CREATE INDEX target_manual_refs_ref_idx ON target_manual_refs (ref);
|
||||
|
||||
CREATE TEMP TABLE target_account_moves AS
|
||||
SELECT DISTINCT am.id
|
||||
FROM account_move am
|
||||
JOIN account_journal aj ON aj.id = am.journal_id
|
||||
WHERE
|
||||
aj.code = 'STJ'
|
||||
AND (
|
||||
am.stock_move_id IN (SELECT id FROM target_stock_moves)
|
||||
OR (
|
||||
am.stock_move_id IS NULL
|
||||
AND COALESCE(am.ref, '') IN (SELECT ref FROM target_manual_refs)
|
||||
)
|
||||
);
|
||||
|
||||
CREATE INDEX target_account_moves_id_idx ON target_account_moves (id);
|
||||
|
||||
CREATE TEMP TABLE target_account_move_lines AS
|
||||
SELECT aml.id
|
||||
FROM account_move_line aml
|
||||
WHERE aml.move_id IN (SELECT id FROM target_account_moves);
|
||||
|
||||
CREATE INDEX target_account_move_lines_id_idx ON target_account_move_lines (id);
|
||||
|
||||
CREATE TEMP TABLE target_stock_move_lines AS
|
||||
SELECT sml.id
|
||||
FROM stock_move_line sml
|
||||
WHERE sml.move_id IN (SELECT id FROM target_stock_moves);
|
||||
|
||||
CREATE INDEX target_stock_move_lines_id_idx ON target_stock_move_lines (id);
|
||||
|
||||
CREATE TEMP TABLE target_inventory_lines AS
|
||||
SELECT sil.id
|
||||
FROM stock_inventory_line sil
|
||||
WHERE sil.inventory_id IN (SELECT id FROM target_inventories);
|
||||
|
||||
CREATE INDEX target_inventory_lines_id_idx ON target_inventory_lines (id);
|
||||
|
||||
CREATE TEMP TABLE target_svls AS
|
||||
SELECT svl.id
|
||||
FROM stock_valuation_layer svl
|
||||
WHERE
|
||||
svl.stock_move_id IN (SELECT id FROM target_stock_moves)
|
||||
OR svl.account_move_id IN (SELECT id FROM target_account_moves);
|
||||
|
||||
CREATE INDEX target_svls_id_idx ON target_svls (id);
|
||||
|
||||
-- Preview counts first
|
||||
SELECT 'target_inventories' AS label, COUNT(*) AS total FROM target_inventories;
|
||||
SELECT 'target_inventory_lines' AS label, COUNT(*) AS total FROM target_inventory_lines;
|
||||
SELECT 'target_stock_moves' AS label, COUNT(*) AS total FROM target_stock_moves;
|
||||
SELECT 'target_stock_move_lines' AS label, COUNT(*) AS total FROM target_stock_move_lines;
|
||||
SELECT 'target_manual_refs' AS label, COUNT(*) AS total FROM target_manual_refs;
|
||||
SELECT 'target_account_moves' AS label, COUNT(*) AS total FROM target_account_moves;
|
||||
SELECT 'target_account_move_lines' AS label, COUNT(*) AS total FROM target_account_move_lines;
|
||||
SELECT 'target_svls' AS label, COUNT(*) AS total FROM target_svls;
|
||||
|
||||
-- Expected at preparation time:
|
||||
-- target_inventories = 1
|
||||
-- target_stock_moves = 99
|
||||
-- target_manual_refs = 99
|
||||
-- target_account_moves = 99 (73 stock-linked STJ + 26 manual STJ)
|
||||
-- Verify again at execution time.
|
||||
|
||||
DELETE FROM account_partial_reconcile
|
||||
WHERE
|
||||
debit_move_id IN (SELECT id FROM target_account_move_lines)
|
||||
OR credit_move_id IN (SELECT id FROM target_account_move_lines);
|
||||
|
||||
DELETE FROM account_analytic_tag_account_move_line_rel
|
||||
WHERE account_move_line_id IN (SELECT id FROM target_account_move_lines);
|
||||
|
||||
DELETE FROM account_move_line_account_tax_rel
|
||||
WHERE account_move_line_id IN (SELECT id FROM target_account_move_lines);
|
||||
|
||||
DELETE FROM stock_valuation_layer
|
||||
WHERE id IN (SELECT id FROM target_svls);
|
||||
|
||||
DELETE FROM account_move_line
|
||||
WHERE id IN (SELECT id FROM target_account_move_lines);
|
||||
|
||||
DELETE FROM account_move
|
||||
WHERE id IN (SELECT id FROM target_account_moves);
|
||||
|
||||
DELETE FROM stock_move_line
|
||||
WHERE id IN (SELECT id FROM target_stock_move_lines);
|
||||
|
||||
DELETE FROM stock_move
|
||||
WHERE id IN (SELECT id FROM target_stock_moves);
|
||||
|
||||
DELETE FROM stock_inventory_line
|
||||
WHERE id IN (SELECT id FROM target_inventory_lines);
|
||||
|
||||
DELETE FROM stock_inventory
|
||||
WHERE id IN (SELECT id FROM target_inventories);
|
||||
|
||||
SELECT 'remaining_stj_target' AS label, COUNT(*) AS total
|
||||
FROM account_move am
|
||||
JOIN account_journal aj ON aj.id = am.journal_id
|
||||
WHERE
|
||||
aj.code = 'STJ'
|
||||
AND (
|
||||
am.stock_move_id IN (SELECT id FROM target_stock_moves)
|
||||
OR (
|
||||
am.stock_move_id IS NULL
|
||||
AND COALESCE(am.ref, '') IN (SELECT ref FROM target_manual_refs)
|
||||
)
|
||||
);
|
||||
|
||||
SELECT 'remaining_target_inventory' AS label, COUNT(*) AS total
|
||||
FROM stock_inventory
|
||||
WHERE id IN (22);
|
||||
|
||||
COMMIT;
|
||||
Reference in New Issue
Block a user