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