blob: 531f10d3f996a1a6b54041b2dea7280f9642d9b8 [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
Gauravf1e28e02019-02-13 16:46:24 +053010from erpnext.regional.italy import fiscal_regimes, tax_exemption_reasons, mode_of_payment_codes, vat_collectability_options
Gaurava4aa80f2019-01-06 12:40:28 +053011
12def setup(company=None, patch=True):
Saurabh9fcfc632019-02-20 13:03:50 +053013 make_custom_fields()
14 setup_report()
marination29d7a7e2020-05-27 21:53:01 +053015 add_permissions()
Gaurava4aa80f2019-01-06 12:40:28 +053016
17def make_custom_fields(update=True):
Saurabh9fcfc632019-02-20 13:03:50 +053018 invoice_item_fields = [
19 dict(fieldname='tax_rate', label='Tax Rate',
Gauravf1e28e02019-02-13 16:46:24 +053020 fieldtype='Float', insert_after='description',
21 print_hide=1, hidden=1, read_only=1),
22 dict(fieldname='tax_amount', label='Tax Amount',
23 fieldtype='Currency', insert_after='tax_rate',
24 print_hide=1, hidden=1, read_only=1, options="currency"),
25 dict(fieldname='total_amount', label='Total Amount',
26 fieldtype='Currency', insert_after='tax_amount',
27 print_hide=1, hidden=1, read_only=1, options="currency")
Saurabh9fcfc632019-02-20 13:03:50 +053028 ]
Gauravf1e28e02019-02-13 16:46:24 +053029
Rohit Waghchaure22ebaf12019-03-07 15:18:49 +053030 customer_po_fields = [
31 dict(fieldname='customer_po_details', label='Customer PO',
32 fieldtype='Section Break', insert_after='image'),
33 dict(fieldname='customer_po_no', label='Customer PO No',
34 fieldtype='Data', insert_after='customer_po_details',
35 fetch_from = 'sales_order.po_no',
Rohit Waghchaure1b7059b2019-03-12 17:44:29 +053036 print_hide=1, allow_on_submit=1, fetch_if_empty= 1, read_only=1, no_copy=1),
Rohit Waghchaure22ebaf12019-03-07 15:18:49 +053037 dict(fieldname='customer_po_clm_brk', label='',
38 fieldtype='Column Break', insert_after='customer_po_no',
39 print_hide=1, read_only=1),
40 dict(fieldname='customer_po_date', label='Customer PO Date',
41 fieldtype='Date', insert_after='customer_po_clm_brk',
42 fetch_from = 'sales_order.po_date',
Rohit Waghchaure1b7059b2019-03-12 17:44:29 +053043 print_hide=1, allow_on_submit=1, fetch_if_empty= 1, read_only=1, no_copy=1)
Rohit Waghchaure22ebaf12019-03-07 15:18:49 +053044 ]
45
Saurabh9fcfc632019-02-20 13:03:50 +053046 custom_fields = {
47 'Company': [
48 dict(fieldname='sb_e_invoicing', label='E-Invoicing',
49 fieldtype='Section Break', insert_after='date_of_establishment', print_hide=1),
50 dict(fieldname='fiscal_regime', label='Fiscal Regime',
51 fieldtype='Select', insert_after='sb_e_invoicing', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +053052 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), fiscal_regimes))),
Saurabh9fcfc632019-02-20 13:03:50 +053053 dict(fieldname='fiscal_code', label='Fiscal Code', fieldtype='Data', insert_after='fiscal_regime', print_hide=1,
54 description=_("Applicable if the company is an Individual or a Proprietorship")),
55 dict(fieldname='vat_collectability', label='VAT Collectability',
56 fieldtype='Select', insert_after='fiscal_code', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +053057 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), vat_collectability_options))),
Saurabh9fcfc632019-02-20 13:03:50 +053058 dict(fieldname='cb_e_invoicing1', fieldtype='Column Break', insert_after='vat_collectability', print_hide=1),
59 dict(fieldname='registrar_office_province', label='Province of the Registrar Office',
60 fieldtype='Data', insert_after='cb_e_invoicing1', print_hide=1, length=2),
61 dict(fieldname='registration_number', label='Registration Number',
62 fieldtype='Data', insert_after='registrar_office_province', print_hide=1, length=20),
63 dict(fieldname='share_capital_amount', label='Share Capital',
64 fieldtype='Currency', insert_after='registration_number', print_hide=1,
65 description=_('Applicable if the company is SpA, SApA or SRL')),
66 dict(fieldname='no_of_members', label='No of Members',
67 fieldtype='Select', insert_after='share_capital_amount', print_hide=1,
68 options="\nSU-Socio Unico\nSM-Piu Soci", description=_("Applicable if the company is a limited liability company")),
69 dict(fieldname='liquidation_state', label='Liquidation State',
70 fieldtype='Select', insert_after='no_of_members', print_hide=1,
71 options="\nLS-In Liquidazione\nLN-Non in Liquidazione")
72 ],
73 'Sales Taxes and Charges': [
74 dict(fieldname='tax_exemption_reason', label='Tax Exemption Reason',
75 fieldtype='Select', insert_after='included_in_print_rate', print_hide=1,
76 depends_on='eval:doc.charge_type!="Actual" && doc.rate==0.0',
Gauravb30a9b12019-03-01 12:33:19 +053077 options="\n" + "\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), tax_exemption_reasons))),
Saurabh9fcfc632019-02-20 13:03:50 +053078 dict(fieldname='tax_exemption_law', label='Tax Exempt Under',
79 fieldtype='Text', insert_after='tax_exemption_reason', print_hide=1,
80 depends_on='eval:doc.charge_type!="Actual" && doc.rate==0.0')
81 ],
82 'Customer': [
83 dict(fieldname='fiscal_code', label='Fiscal Code', fieldtype='Data', insert_after='tax_id', print_hide=1),
84 dict(fieldname='recipient_code', label='Recipient Code',
85 fieldtype='Data', insert_after='fiscal_code', print_hide=1, default="0000000"),
86 dict(fieldname='pec', label='Recipient PEC',
87 fieldtype='Data', insert_after='fiscal_code', print_hide=1),
88 dict(fieldname='is_public_administration', label='Is Public Administration',
89 fieldtype='Check', insert_after='is_internal_customer', print_hide=1,
90 description=_("Set this if the customer is a Public Administration company."),
91 depends_on='eval:doc.customer_type=="Company"'),
92 dict(fieldname='first_name', label='First Name', fieldtype='Data',
93 insert_after='salutation', print_hide=1, depends_on='eval:doc.customer_type!="Company"'),
94 dict(fieldname='last_name', label='Last Name', fieldtype='Data',
95 insert_after='first_name', print_hide=1, depends_on='eval:doc.customer_type!="Company"')
96 ],
97 'Mode of Payment': [
98 dict(fieldname='mode_of_payment_code', label='Code',
99 fieldtype='Select', insert_after='included_in_print_rate', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +0530100 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), mode_of_payment_codes)))
Saurabh9fcfc632019-02-20 13:03:50 +0530101 ],
102 'Payment Schedule': [
103 dict(fieldname='mode_of_payment_code', label='Code',
104 fieldtype='Select', insert_after='mode_of_payment', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +0530105 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), mode_of_payment_codes)),
Saurabh9fcfc632019-02-20 13:03:50 +0530106 fetch_from="mode_of_payment.mode_of_payment_code", read_only=1),
107 dict(fieldname='bank_account', label='Bank Account',
108 fieldtype='Link', insert_after='mode_of_payment_code', print_hide=1,
109 options="Bank Account"),
Gauravb30a9b12019-03-01 12:33:19 +0530110 dict(fieldname='bank_account_name', label='Bank Name',
Saurabh9fcfc632019-02-20 13:03:50 +0530111 fieldtype='Data', insert_after='bank_account', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +0530112 fetch_from="bank_account.bank", read_only=1),
Saurabh9fcfc632019-02-20 13:03:50 +0530113 dict(fieldname='bank_account_no', label='Bank Account No',
114 fieldtype='Data', insert_after='bank_account_name', print_hide=1,
115 fetch_from="bank_account.bank_account_no", read_only=1),
116 dict(fieldname='bank_account_iban', label='IBAN',
117 fieldtype='Data', insert_after='bank_account_name', print_hide=1,
118 fetch_from="bank_account.iban", read_only=1),
Gauravb30a9b12019-03-01 12:33:19 +0530119 dict(fieldname='bank_account_swift_number', label='Swift Code (BIC)',
120 fieldtype='Data', insert_after='bank_account_iban', print_hide=1,
121 fetch_from="bank_account.swift_number", read_only=1),
Saurabh9fcfc632019-02-20 13:03:50 +0530122 ],
123 "Sales Invoice": [
124 dict(fieldname='vat_collectability', label='VAT Collectability',
125 fieldtype='Select', insert_after='taxes_and_charges', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +0530126 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), vat_collectability_options)),
Saurabh9fcfc632019-02-20 13:03:50 +0530127 fetch_from="company.vat_collectability"),
128 dict(fieldname='sb_e_invoicing_reference', label='E-Invoicing',
Saqib Ansaricee36702021-02-01 15:45:26 +0530129 fieldtype='Section Break', insert_after='against_income_account', print_hide=1),
Saurabh9fcfc632019-02-20 13:03:50 +0530130 dict(fieldname='company_fiscal_code', label='Company Fiscal Code',
Sagar Voraba76f872021-03-29 20:18:45 +0530131 fieldtype='Data', insert_after='sb_e_invoicing_reference', print_hide=1, read_only=1,
Saurabh9fcfc632019-02-20 13:03:50 +0530132 fetch_from="company.fiscal_code"),
133 dict(fieldname='company_fiscal_regime', label='Company Fiscal Regime',
134 fieldtype='Data', insert_after='company_fiscal_code', print_hide=1, read_only=1,
135 fetch_from="company.fiscal_regime"),
136 dict(fieldname='cb_e_invoicing_reference', fieldtype='Column Break',
137 insert_after='company_fiscal_regime', print_hide=1),
138 dict(fieldname='customer_fiscal_code', label='Customer Fiscal Code',
139 fieldtype='Data', insert_after='cb_e_invoicing_reference', read_only=1,
140 fetch_from="customer.fiscal_code"),
Saqib Ansari032246d2021-04-09 12:08:24 +0530141 dict(fieldname='type_of_document', label='Type of Document',
142 fieldtype='Select', insert_after='customer_fiscal_code',
143 options='\nTD01\nTD02\nTD03\nTD04\nTD05\nTD06\nTD16\nTD17\nTD18\nTD19\nTD20\nTD21\nTD22\nTD23\nTD24\nTD25\nTD26\nTD27'),
Saurabh9fcfc632019-02-20 13:03:50 +0530144 ],
145 'Purchase Invoice Item': invoice_item_fields,
Gauravf1e28e02019-02-13 16:46:24 +0530146 'Sales Order Item': invoice_item_fields,
147 'Delivery Note Item': invoice_item_fields,
Rohit Waghchaure22ebaf12019-03-07 15:18:49 +0530148 'Sales Invoice Item': invoice_item_fields + customer_po_fields,
Gauravf1e28e02019-02-13 16:46:24 +0530149 'Quotation Item': invoice_item_fields,
150 'Purchase Order Item': invoice_item_fields,
151 'Purchase Receipt Item': invoice_item_fields,
152 'Supplier Quotation Item': invoice_item_fields,
Saurabh9fcfc632019-02-20 13:03:50 +0530153 'Address': [
154 dict(fieldname='country_code', label='Country Code',
Rohit Waghchaure74cfe572019-02-26 20:08:26 +0530155 fieldtype='Data', insert_after='country', print_hide=1, read_only=0,
Saurabh9fcfc632019-02-20 13:03:50 +0530156 fetch_from="country.code"),
157 dict(fieldname='state_code', label='State Code',
158 fieldtype='Data', insert_after='state', print_hide=1)
hello@openetech.com70214022019-10-16 23:38:51 +0530159 ],
160 'Purchase Invoice': [
161 dict(fieldname='document_type', label='Document Type',
162 fieldtype='Data', insert_after='company', print_hide=1, read_only=1
163 ),
164 dict(fieldname='destination_code', label='Destination Code',
165 fieldtype='Data', insert_after='company', print_hide=1, read_only=1
166 ),
167 dict(fieldname='imported_grand_total', label='Imported Grand Total',
168 fieldtype='Data', insert_after='update_auto_repeat_reference', print_hide=1, read_only=1
169 )
170 ],
171 'Purchase Taxes and Charges': [
172 dict(fieldname='tax_rate', label='Tax Rate',
173 fieldtype='Data', insert_after='parenttype', print_hide=1, read_only=0
174 )
175 ],
176 'Supplier': [
177 dict(fieldname='fiscal_code', label='Fiscal Code',
178 fieldtype='Data', insert_after='tax_id', print_hide=1, read_only=1
179 ),
180 dict(fieldname='fiscal_regime', label='Fiscal Regime',
181 fieldtype='Select', insert_after='fiscal_code', print_hide=1, read_only=1,
182 options= "\nRF01\nRF02\nRF04\nRF05\nRF06\nRF07\nRF08\nRF09\nRF10\nRF11\nRF12\nRF13\nRF14\nRF15\nRF16\nRF17\nRF18\nRF19"
183 )
Saurabh9fcfc632019-02-20 13:03:50 +0530184 ]
185 }
Gaurava4aa80f2019-01-06 12:40:28 +0530186
Saurabh9fcfc632019-02-20 13:03:50 +0530187 create_custom_fields(custom_fields, ignore_validate = frappe.flags.in_patch, update=update)
Gauravf1e28e02019-02-13 16:46:24 +0530188
189def setup_report():
Saurabh9fcfc632019-02-20 13:03:50 +0530190 report_name = 'Electronic Invoice Register'
barredterra1521b312021-03-03 12:33:48 +0100191 frappe.db.set_value("Report", report_name, "disabled", 0)
Gauravf1e28e02019-02-13 16:46:24 +0530192
Saurabh9fcfc632019-02-20 13:03:50 +0530193 if not frappe.db.get_value('Custom Role', dict(report=report_name)):
194 frappe.get_doc(dict(
195 doctype='Custom Role',
196 report=report_name,
197 roles= [
198 dict(role='Accounts User'),
199 dict(role='Accounts Manager')
200 ]
201 )).insert()
marination29d7a7e2020-05-27 21:53:01 +0530202
203def add_permissions():
204 doctype = 'Import Supplier Invoice'
205 add_permission(doctype, 'All', 0)
206
207 for role in ('Accounts Manager', 'Accounts User','Purchase User', 'Auditor'):
208 add_permission(doctype, role, 0)
209 update_permission_property(doctype, role, 0, 'print', 1)
210 update_permission_property(doctype, role, 0, 'report', 1)
211
212 if role in ('Accounts Manager', 'Accounts User'):
213 update_permission_property(doctype, role, 0, 'write', 1)
214 update_permission_property(doctype, role, 0, 'create', 1)
215
216 update_permission_property(doctype, 'Accounts Manager', 0, 'delete', 1)
217 add_permission(doctype, 'Accounts Manager', 1)
218 update_permission_property(doctype, 'Accounts Manager', 1, 'write', 1)
Sagar Voraba76f872021-03-29 20:18:45 +0530219 update_permission_property(doctype, 'Accounts Manager', 1, 'create', 1)