blob: 23406ea85a66b39fb948fd42b57252bbb7a94264 [file] [log] [blame]
Gaurava4aa80f2019-01-06 12:40:28 +05301# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2# License: GNU General Public License v3. See license.txt
3# coding=utf-8
4
Gaurava4aa80f2019-01-06 12:40:28 +05305
6import frappe
Gauravf1e28e02019-02-13 16:46:24 +05307from frappe import _
Gaurava4aa80f2019-01-06 12:40:28 +05308from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
marination29d7a7e2020-05-27 21:53:01 +05309from frappe.permissions import add_permission, update_permission_property
Akhil Narang3effaf22024-03-27 11:37:26 +053010
Ankush Menat494bd9e2022-03-28 18:52:46 +053011from erpnext.regional.italy import (
12 fiscal_regimes,
Ankush Menat494bd9e2022-03-28 18:52:46 +053013 mode_of_payment_codes,
Akhil Narang3effaf22024-03-27 11:37:26 +053014 tax_exemption_reasons,
Ankush Menat494bd9e2022-03-28 18:52:46 +053015 vat_collectability_options,
16)
17
Gaurava4aa80f2019-01-06 12:40:28 +053018
19def setup(company=None, patch=True):
Saurabh9fcfc632019-02-20 13:03:50 +053020 make_custom_fields()
21 setup_report()
marination29d7a7e2020-05-27 21:53:01 +053022 add_permissions()
Gaurava4aa80f2019-01-06 12:40:28 +053023
Ankush Menat494bd9e2022-03-28 18:52:46 +053024
Gaurava4aa80f2019-01-06 12:40:28 +053025def make_custom_fields(update=True):
Saurabh9fcfc632019-02-20 13:03:50 +053026 invoice_item_fields = [
Ankush Menat494bd9e2022-03-28 18:52:46 +053027 dict(
28 fieldname="tax_rate",
29 label="Tax Rate",
30 fieldtype="Float",
31 insert_after="description",
32 print_hide=1,
33 hidden=1,
34 read_only=1,
35 ),
36 dict(
37 fieldname="tax_amount",
38 label="Tax Amount",
39 fieldtype="Currency",
40 insert_after="tax_rate",
41 print_hide=1,
42 hidden=1,
43 read_only=1,
44 options="currency",
45 ),
46 dict(
47 fieldname="total_amount",
48 label="Total Amount",
49 fieldtype="Currency",
50 insert_after="tax_amount",
51 print_hide=1,
52 hidden=1,
53 read_only=1,
54 options="currency",
55 ),
Saurabh9fcfc632019-02-20 13:03:50 +053056 ]
Gauravf1e28e02019-02-13 16:46:24 +053057
Rohit Waghchaure22ebaf12019-03-07 15:18:49 +053058 customer_po_fields = [
Ankush Menat494bd9e2022-03-28 18:52:46 +053059 dict(
60 fieldname="customer_po_details",
61 label="Customer PO",
62 fieldtype="Section Break",
63 insert_after="image",
64 ),
65 dict(
66 fieldname="customer_po_no",
67 label="Customer PO No",
68 fieldtype="Data",
69 insert_after="customer_po_details",
70 fetch_from="sales_order.po_no",
71 print_hide=1,
72 allow_on_submit=1,
73 fetch_if_empty=1,
74 read_only=1,
75 no_copy=1,
76 ),
77 dict(
78 fieldname="customer_po_clm_brk",
79 label="",
80 fieldtype="Column Break",
81 insert_after="customer_po_no",
82 print_hide=1,
83 read_only=1,
84 ),
85 dict(
86 fieldname="customer_po_date",
87 label="Customer PO Date",
88 fieldtype="Date",
89 insert_after="customer_po_clm_brk",
90 fetch_from="sales_order.po_date",
91 print_hide=1,
92 allow_on_submit=1,
93 fetch_if_empty=1,
94 read_only=1,
95 no_copy=1,
96 ),
Rohit Waghchaure22ebaf12019-03-07 15:18:49 +053097 ]
98
Saurabh9fcfc632019-02-20 13:03:50 +053099 custom_fields = {
Ankush Menat494bd9e2022-03-28 18:52:46 +0530100 "Company": [
101 dict(
102 fieldname="sb_e_invoicing",
103 label="E-Invoicing",
104 fieldtype="Section Break",
105 insert_after="date_of_establishment",
106 print_hide=1,
107 ),
108 dict(
109 fieldname="fiscal_regime",
110 label="Fiscal Regime",
111 fieldtype="Select",
112 insert_after="sb_e_invoicing",
113 print_hide=1,
114 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding="utf-8"), fiscal_regimes)),
115 ),
116 dict(
117 fieldname="fiscal_code",
118 label="Fiscal Code",
119 fieldtype="Data",
120 insert_after="fiscal_regime",
121 print_hide=1,
122 description=_("Applicable if the company is an Individual or a Proprietorship"),
123 ),
124 dict(
125 fieldname="vat_collectability",
126 label="VAT Collectability",
127 fieldtype="Select",
128 insert_after="fiscal_code",
129 print_hide=1,
130 options="\n".join(
131 map(lambda x: frappe.safe_decode(x, encoding="utf-8"), vat_collectability_options)
132 ),
133 ),
134 dict(
135 fieldname="cb_e_invoicing1",
136 fieldtype="Column Break",
137 insert_after="vat_collectability",
138 print_hide=1,
139 ),
140 dict(
141 fieldname="registrar_office_province",
142 label="Province of the Registrar Office",
143 fieldtype="Data",
144 insert_after="cb_e_invoicing1",
145 print_hide=1,
146 length=2,
147 ),
148 dict(
149 fieldname="registration_number",
150 label="Registration Number",
151 fieldtype="Data",
152 insert_after="registrar_office_province",
153 print_hide=1,
154 length=20,
155 ),
156 dict(
157 fieldname="share_capital_amount",
158 label="Share Capital",
159 fieldtype="Currency",
160 insert_after="registration_number",
161 print_hide=1,
162 description=_("Applicable if the company is SpA, SApA or SRL"),
163 ),
164 dict(
165 fieldname="no_of_members",
166 label="No of Members",
167 fieldtype="Select",
168 insert_after="share_capital_amount",
169 print_hide=1,
170 options="\nSU-Socio Unico\nSM-Piu Soci",
171 description=_("Applicable if the company is a limited liability company"),
172 ),
173 dict(
174 fieldname="liquidation_state",
175 label="Liquidation State",
176 fieldtype="Select",
177 insert_after="no_of_members",
178 print_hide=1,
179 options="\nLS-In Liquidazione\nLN-Non in Liquidazione",
180 ),
Saurabh9fcfc632019-02-20 13:03:50 +0530181 ],
Ankush Menat494bd9e2022-03-28 18:52:46 +0530182 "Sales Taxes and Charges": [
183 dict(
184 fieldname="tax_exemption_reason",
185 label="Tax Exemption Reason",
186 fieldtype="Select",
187 insert_after="included_in_print_rate",
188 print_hide=1,
Saurabh9fcfc632019-02-20 13:03:50 +0530189 depends_on='eval:doc.charge_type!="Actual" && doc.rate==0.0',
Ankush Menat494bd9e2022-03-28 18:52:46 +0530190 options="\n"
191 + "\n".join(map(lambda x: frappe.safe_decode(x, encoding="utf-8"), tax_exemption_reasons)),
192 ),
193 dict(
194 fieldname="tax_exemption_law",
195 label="Tax Exempt Under",
196 fieldtype="Text",
197 insert_after="tax_exemption_reason",
198 print_hide=1,
199 depends_on='eval:doc.charge_type!="Actual" && doc.rate==0.0',
200 ),
Saurabh9fcfc632019-02-20 13:03:50 +0530201 ],
Ankush Menat494bd9e2022-03-28 18:52:46 +0530202 "Customer": [
203 dict(
204 fieldname="fiscal_code",
205 label="Fiscal Code",
206 fieldtype="Data",
207 insert_after="tax_id",
208 print_hide=1,
209 ),
210 dict(
211 fieldname="recipient_code",
212 label="Recipient Code",
213 fieldtype="Data",
214 insert_after="fiscal_code",
215 print_hide=1,
216 default="0000000",
217 ),
218 dict(
219 fieldname="pec",
220 label="Recipient PEC",
221 fieldtype="Data",
222 insert_after="fiscal_code",
223 print_hide=1,
224 ),
225 dict(
226 fieldname="is_public_administration",
227 label="Is Public Administration",
228 fieldtype="Check",
229 insert_after="is_internal_customer",
230 print_hide=1,
Saurabh9fcfc632019-02-20 13:03:50 +0530231 description=_("Set this if the customer is a Public Administration company."),
Ankush Menat494bd9e2022-03-28 18:52:46 +0530232 depends_on='eval:doc.customer_type=="Company"',
233 ),
234 dict(
235 fieldname="first_name",
236 label="First Name",
237 fieldtype="Data",
238 insert_after="salutation",
239 print_hide=1,
240 depends_on='eval:doc.customer_type!="Company"',
241 ),
242 dict(
243 fieldname="last_name",
244 label="Last Name",
245 fieldtype="Data",
246 insert_after="first_name",
247 print_hide=1,
248 depends_on='eval:doc.customer_type!="Company"',
249 ),
Saurabh9fcfc632019-02-20 13:03:50 +0530250 ],
Ankush Menat494bd9e2022-03-28 18:52:46 +0530251 "Mode of Payment": [
252 dict(
253 fieldname="mode_of_payment_code",
254 label="Code",
255 fieldtype="Select",
256 insert_after="included_in_print_rate",
257 print_hide=1,
258 options="\n".join(
259 map(lambda x: frappe.safe_decode(x, encoding="utf-8"), mode_of_payment_codes)
260 ),
261 )
Saurabh9fcfc632019-02-20 13:03:50 +0530262 ],
Ankush Menat494bd9e2022-03-28 18:52:46 +0530263 "Payment Schedule": [
264 dict(
265 fieldname="mode_of_payment_code",
266 label="Code",
267 fieldtype="Select",
268 insert_after="mode_of_payment",
269 print_hide=1,
270 options="\n".join(
271 map(lambda x: frappe.safe_decode(x, encoding="utf-8"), mode_of_payment_codes)
272 ),
273 fetch_from="mode_of_payment.mode_of_payment_code",
274 read_only=1,
275 ),
276 dict(
277 fieldname="bank_account",
278 label="Bank Account",
279 fieldtype="Link",
280 insert_after="mode_of_payment_code",
281 print_hide=1,
282 options="Bank Account",
283 ),
284 dict(
285 fieldname="bank_account_name",
286 label="Bank Name",
287 fieldtype="Data",
288 insert_after="bank_account",
289 print_hide=1,
290 fetch_from="bank_account.bank",
291 read_only=1,
292 ),
293 dict(
294 fieldname="bank_account_no",
295 label="Bank Account No",
296 fieldtype="Data",
297 insert_after="bank_account_name",
298 print_hide=1,
299 fetch_from="bank_account.bank_account_no",
300 read_only=1,
301 ),
302 dict(
303 fieldname="bank_account_iban",
304 label="IBAN",
305 fieldtype="Data",
306 insert_after="bank_account_name",
307 print_hide=1,
308 fetch_from="bank_account.iban",
309 read_only=1,
310 ),
311 dict(
312 fieldname="bank_account_swift_number",
313 label="Swift Code (BIC)",
314 fieldtype="Data",
315 insert_after="bank_account_iban",
316 print_hide=1,
317 fetch_from="bank_account.swift_number",
318 read_only=1,
319 ),
Saurabh9fcfc632019-02-20 13:03:50 +0530320 ],
321 "Sales Invoice": [
Ankush Menat494bd9e2022-03-28 18:52:46 +0530322 dict(
323 fieldname="vat_collectability",
324 label="VAT Collectability",
325 fieldtype="Select",
326 insert_after="taxes_and_charges",
327 print_hide=1,
328 options="\n".join(
329 map(lambda x: frappe.safe_decode(x, encoding="utf-8"), vat_collectability_options)
hello@openetech.com70214022019-10-16 23:38:51 +0530330 ),
Ankush Menat494bd9e2022-03-28 18:52:46 +0530331 fetch_from="company.vat_collectability",
332 ),
333 dict(
334 fieldname="sb_e_invoicing_reference",
335 label="E-Invoicing",
336 fieldtype="Section Break",
337 insert_after="against_income_account",
338 print_hide=1,
339 ),
340 dict(
341 fieldname="company_fiscal_code",
342 label="Company Fiscal Code",
343 fieldtype="Data",
344 insert_after="sb_e_invoicing_reference",
345 print_hide=1,
346 read_only=1,
347 fetch_from="company.fiscal_code",
348 ),
349 dict(
350 fieldname="company_fiscal_regime",
351 label="Company Fiscal Regime",
352 fieldtype="Data",
353 insert_after="company_fiscal_code",
354 print_hide=1,
355 read_only=1,
356 fetch_from="company.fiscal_regime",
357 ),
358 dict(
359 fieldname="cb_e_invoicing_reference",
360 fieldtype="Column Break",
361 insert_after="company_fiscal_regime",
362 print_hide=1,
363 ),
364 dict(
365 fieldname="customer_fiscal_code",
366 label="Customer Fiscal Code",
367 fieldtype="Data",
368 insert_after="cb_e_invoicing_reference",
369 read_only=1,
370 fetch_from="customer.fiscal_code",
371 ),
372 dict(
373 fieldname="type_of_document",
374 label="Type of Document",
375 fieldtype="Select",
376 insert_after="customer_fiscal_code",
377 options="\nTD01\nTD02\nTD03\nTD04\nTD05\nTD06\nTD16\nTD17\nTD18\nTD19\nTD20\nTD21\nTD22\nTD23\nTD24\nTD25\nTD26\nTD27",
378 ),
hello@openetech.com70214022019-10-16 23:38:51 +0530379 ],
Ankush Menat494bd9e2022-03-28 18:52:46 +0530380 "Purchase Invoice Item": invoice_item_fields,
381 "Sales Order Item": invoice_item_fields,
382 "Delivery Note Item": invoice_item_fields,
383 "Sales Invoice Item": invoice_item_fields + customer_po_fields,
384 "Quotation Item": invoice_item_fields,
385 "Purchase Order Item": invoice_item_fields,
386 "Purchase Receipt Item": invoice_item_fields,
387 "Supplier Quotation Item": invoice_item_fields,
388 "Address": [
389 dict(
390 fieldname="country_code",
391 label="Country Code",
392 fieldtype="Data",
393 insert_after="country",
394 print_hide=1,
395 read_only=0,
396 fetch_from="country.code",
397 ),
398 dict(
399 fieldname="state_code",
400 label="State Code",
401 fieldtype="Data",
402 insert_after="state",
403 print_hide=1,
404 ),
hello@openetech.com70214022019-10-16 23:38:51 +0530405 ],
Ankush Menat494bd9e2022-03-28 18:52:46 +0530406 "Purchase Invoice": [
407 dict(
408 fieldname="document_type",
409 label="Document Type",
410 fieldtype="Data",
411 insert_after="company",
412 print_hide=1,
413 read_only=1,
414 ),
415 dict(
416 fieldname="destination_code",
417 label="Destination Code",
418 fieldtype="Data",
419 insert_after="company",
420 print_hide=1,
421 read_only=1,
422 ),
423 dict(
424 fieldname="imported_grand_total",
425 label="Imported Grand Total",
426 fieldtype="Data",
427 insert_after="update_auto_repeat_reference",
428 print_hide=1,
429 read_only=1,
430 ),
431 ],
432 "Purchase Taxes and Charges": [
433 dict(
434 fieldname="tax_rate",
435 label="Tax Rate",
436 fieldtype="Data",
437 insert_after="parenttype",
438 print_hide=1,
439 read_only=0,
440 )
441 ],
442 "Supplier": [
443 dict(
444 fieldname="fiscal_code",
445 label="Fiscal Code",
446 fieldtype="Data",
447 insert_after="tax_id",
448 print_hide=1,
449 read_only=1,
450 ),
451 dict(
452 fieldname="fiscal_regime",
453 label="Fiscal Regime",
454 fieldtype="Select",
455 insert_after="fiscal_code",
456 print_hide=1,
457 read_only=1,
458 options="\nRF01\nRF02\nRF04\nRF05\nRF06\nRF07\nRF08\nRF09\nRF10\nRF11\nRF12\nRF13\nRF14\nRF15\nRF16\nRF17\nRF18\nRF19",
459 ),
460 ],
Saurabh9fcfc632019-02-20 13:03:50 +0530461 }
Gaurava4aa80f2019-01-06 12:40:28 +0530462
Ankush Menat494bd9e2022-03-28 18:52:46 +0530463 create_custom_fields(custom_fields, ignore_validate=frappe.flags.in_patch, update=update)
464
Gauravf1e28e02019-02-13 16:46:24 +0530465
466def setup_report():
Ankush Menat494bd9e2022-03-28 18:52:46 +0530467 report_name = "Electronic Invoice Register"
barredterra1521b312021-03-03 12:33:48 +0100468 frappe.db.set_value("Report", report_name, "disabled", 0)
Gauravf1e28e02019-02-13 16:46:24 +0530469
Ankush Menat494bd9e2022-03-28 18:52:46 +0530470 if not frappe.db.get_value("Custom Role", dict(report=report_name)):
471 frappe.get_doc(
472 dict(
473 doctype="Custom Role",
474 report=report_name,
475 roles=[dict(role="Accounts User"), dict(role="Accounts Manager")],
476 )
477 ).insert()
478
marination29d7a7e2020-05-27 21:53:01 +0530479
480def add_permissions():
Ankush Menat494bd9e2022-03-28 18:52:46 +0530481 doctype = "Import Supplier Invoice"
482 add_permission(doctype, "All", 0)
marination29d7a7e2020-05-27 21:53:01 +0530483
Ankush Menat494bd9e2022-03-28 18:52:46 +0530484 for role in ("Accounts Manager", "Accounts User", "Purchase User", "Auditor"):
marination29d7a7e2020-05-27 21:53:01 +0530485 add_permission(doctype, role, 0)
Ankush Menat494bd9e2022-03-28 18:52:46 +0530486 update_permission_property(doctype, role, 0, "print", 1)
487 update_permission_property(doctype, role, 0, "report", 1)
marination29d7a7e2020-05-27 21:53:01 +0530488
Ankush Menat494bd9e2022-03-28 18:52:46 +0530489 if role in ("Accounts Manager", "Accounts User"):
490 update_permission_property(doctype, role, 0, "write", 1)
491 update_permission_property(doctype, role, 0, "create", 1)
marination29d7a7e2020-05-27 21:53:01 +0530492
Ankush Menat494bd9e2022-03-28 18:52:46 +0530493 update_permission_property(doctype, "Accounts Manager", 0, "delete", 1)
494 add_permission(doctype, "Accounts Manager", 1)
495 update_permission_property(doctype, "Accounts Manager", 1, "write", 1)
496 update_permission_property(doctype, "Accounts Manager", 1, "create", 1)