blob: 2d0ad66b0a063c127686754f8ddab9da62a70f24 [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
5from __future__ import unicode_literals
6
7import frappe
Gauravf1e28e02019-02-13 16:46:24 +05308from frappe import _
Gaurava4aa80f2019-01-06 12:40:28 +05309from frappe.custom.doctype.custom_field.custom_field import create_custom_fields
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()
Gaurava4aa80f2019-01-06 12:40:28 +053015
16def make_custom_fields(update=True):
Saurabh9fcfc632019-02-20 13:03:50 +053017 invoice_item_fields = [
18 dict(fieldname='tax_rate', label='Tax Rate',
Gauravf1e28e02019-02-13 16:46:24 +053019 fieldtype='Float', insert_after='description',
20 print_hide=1, hidden=1, read_only=1),
21 dict(fieldname='tax_amount', label='Tax Amount',
22 fieldtype='Currency', insert_after='tax_rate',
23 print_hide=1, hidden=1, read_only=1, options="currency"),
24 dict(fieldname='total_amount', label='Total Amount',
25 fieldtype='Currency', insert_after='tax_amount',
26 print_hide=1, hidden=1, read_only=1, options="currency")
Saurabh9fcfc632019-02-20 13:03:50 +053027 ]
Gauravf1e28e02019-02-13 16:46:24 +053028
Rohit Waghchaure22ebaf12019-03-07 15:18:49 +053029 customer_po_fields = [
30 dict(fieldname='customer_po_details', label='Customer PO',
31 fieldtype='Section Break', insert_after='image'),
32 dict(fieldname='customer_po_no', label='Customer PO No',
33 fieldtype='Data', insert_after='customer_po_details',
34 fetch_from = 'sales_order.po_no',
Rohit Waghchaure1b7059b2019-03-12 17:44:29 +053035 print_hide=1, allow_on_submit=1, fetch_if_empty= 1, read_only=1, no_copy=1),
Rohit Waghchaure22ebaf12019-03-07 15:18:49 +053036 dict(fieldname='customer_po_clm_brk', label='',
37 fieldtype='Column Break', insert_after='customer_po_no',
38 print_hide=1, read_only=1),
39 dict(fieldname='customer_po_date', label='Customer PO Date',
40 fieldtype='Date', insert_after='customer_po_clm_brk',
41 fetch_from = 'sales_order.po_date',
Rohit Waghchaure1b7059b2019-03-12 17:44:29 +053042 print_hide=1, allow_on_submit=1, fetch_if_empty= 1, read_only=1, no_copy=1)
Rohit Waghchaure22ebaf12019-03-07 15:18:49 +053043 ]
44
Saurabh9fcfc632019-02-20 13:03:50 +053045 custom_fields = {
46 'Company': [
47 dict(fieldname='sb_e_invoicing', label='E-Invoicing',
48 fieldtype='Section Break', insert_after='date_of_establishment', print_hide=1),
49 dict(fieldname='fiscal_regime', label='Fiscal Regime',
50 fieldtype='Select', insert_after='sb_e_invoicing', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +053051 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), fiscal_regimes))),
Saurabh9fcfc632019-02-20 13:03:50 +053052 dict(fieldname='fiscal_code', label='Fiscal Code', fieldtype='Data', insert_after='fiscal_regime', print_hide=1,
53 description=_("Applicable if the company is an Individual or a Proprietorship")),
54 dict(fieldname='vat_collectability', label='VAT Collectability',
55 fieldtype='Select', insert_after='fiscal_code', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +053056 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), vat_collectability_options))),
Saurabh9fcfc632019-02-20 13:03:50 +053057 dict(fieldname='cb_e_invoicing1', fieldtype='Column Break', insert_after='vat_collectability', print_hide=1),
58 dict(fieldname='registrar_office_province', label='Province of the Registrar Office',
59 fieldtype='Data', insert_after='cb_e_invoicing1', print_hide=1, length=2),
60 dict(fieldname='registration_number', label='Registration Number',
61 fieldtype='Data', insert_after='registrar_office_province', print_hide=1, length=20),
62 dict(fieldname='share_capital_amount', label='Share Capital',
63 fieldtype='Currency', insert_after='registration_number', print_hide=1,
64 description=_('Applicable if the company is SpA, SApA or SRL')),
65 dict(fieldname='no_of_members', label='No of Members',
66 fieldtype='Select', insert_after='share_capital_amount', print_hide=1,
67 options="\nSU-Socio Unico\nSM-Piu Soci", description=_("Applicable if the company is a limited liability company")),
68 dict(fieldname='liquidation_state', label='Liquidation State',
69 fieldtype='Select', insert_after='no_of_members', print_hide=1,
70 options="\nLS-In Liquidazione\nLN-Non in Liquidazione")
71 ],
72 'Sales Taxes and Charges': [
73 dict(fieldname='tax_exemption_reason', label='Tax Exemption Reason',
74 fieldtype='Select', insert_after='included_in_print_rate', print_hide=1,
75 depends_on='eval:doc.charge_type!="Actual" && doc.rate==0.0',
Gauravb30a9b12019-03-01 12:33:19 +053076 options="\n" + "\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), tax_exemption_reasons))),
Saurabh9fcfc632019-02-20 13:03:50 +053077 dict(fieldname='tax_exemption_law', label='Tax Exempt Under',
78 fieldtype='Text', insert_after='tax_exemption_reason', print_hide=1,
79 depends_on='eval:doc.charge_type!="Actual" && doc.rate==0.0')
80 ],
81 'Customer': [
82 dict(fieldname='fiscal_code', label='Fiscal Code', fieldtype='Data', insert_after='tax_id', print_hide=1),
83 dict(fieldname='recipient_code', label='Recipient Code',
84 fieldtype='Data', insert_after='fiscal_code', print_hide=1, default="0000000"),
85 dict(fieldname='pec', label='Recipient PEC',
86 fieldtype='Data', insert_after='fiscal_code', print_hide=1),
87 dict(fieldname='is_public_administration', label='Is Public Administration',
88 fieldtype='Check', insert_after='is_internal_customer', print_hide=1,
89 description=_("Set this if the customer is a Public Administration company."),
90 depends_on='eval:doc.customer_type=="Company"'),
91 dict(fieldname='first_name', label='First Name', fieldtype='Data',
92 insert_after='salutation', print_hide=1, depends_on='eval:doc.customer_type!="Company"'),
93 dict(fieldname='last_name', label='Last Name', fieldtype='Data',
94 insert_after='first_name', print_hide=1, depends_on='eval:doc.customer_type!="Company"')
95 ],
96 'Mode of Payment': [
97 dict(fieldname='mode_of_payment_code', label='Code',
98 fieldtype='Select', insert_after='included_in_print_rate', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +053099 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), mode_of_payment_codes)))
Saurabh9fcfc632019-02-20 13:03:50 +0530100 ],
101 'Payment Schedule': [
102 dict(fieldname='mode_of_payment_code', label='Code',
103 fieldtype='Select', insert_after='mode_of_payment', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +0530104 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), mode_of_payment_codes)),
Saurabh9fcfc632019-02-20 13:03:50 +0530105 fetch_from="mode_of_payment.mode_of_payment_code", read_only=1),
106 dict(fieldname='bank_account', label='Bank Account',
107 fieldtype='Link', insert_after='mode_of_payment_code', print_hide=1,
108 options="Bank Account"),
Gauravb30a9b12019-03-01 12:33:19 +0530109 dict(fieldname='bank_account_name', label='Bank Name',
Saurabh9fcfc632019-02-20 13:03:50 +0530110 fieldtype='Data', insert_after='bank_account', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +0530111 fetch_from="bank_account.bank", read_only=1),
Saurabh9fcfc632019-02-20 13:03:50 +0530112 dict(fieldname='bank_account_no', label='Bank Account No',
113 fieldtype='Data', insert_after='bank_account_name', print_hide=1,
114 fetch_from="bank_account.bank_account_no", read_only=1),
115 dict(fieldname='bank_account_iban', label='IBAN',
116 fieldtype='Data', insert_after='bank_account_name', print_hide=1,
117 fetch_from="bank_account.iban", read_only=1),
Gauravb30a9b12019-03-01 12:33:19 +0530118 dict(fieldname='bank_account_swift_number', label='Swift Code (BIC)',
119 fieldtype='Data', insert_after='bank_account_iban', print_hide=1,
120 fetch_from="bank_account.swift_number", read_only=1),
Saurabh9fcfc632019-02-20 13:03:50 +0530121 ],
122 "Sales Invoice": [
123 dict(fieldname='vat_collectability', label='VAT Collectability',
124 fieldtype='Select', insert_after='taxes_and_charges', print_hide=1,
Gauravb30a9b12019-03-01 12:33:19 +0530125 options="\n".join(map(lambda x: frappe.safe_decode(x, encoding='utf-8'), vat_collectability_options)),
Saurabh9fcfc632019-02-20 13:03:50 +0530126 fetch_from="company.vat_collectability"),
127 dict(fieldname='sb_e_invoicing_reference', label='E-Invoicing',
128 fieldtype='Section Break', insert_after='pos_total_qty', print_hide=1),
129 dict(fieldname='company_tax_id', label='Company Tax ID',
130 fieldtype='Data', insert_after='sb_e_invoicing_reference', print_hide=1, read_only=1,
131 fetch_from="company.tax_id"),
132 dict(fieldname='company_fiscal_code', label='Company Fiscal Code',
133 fieldtype='Data', insert_after='company_tax_id', print_hide=1, read_only=1,
134 fetch_from="company.fiscal_code"),
135 dict(fieldname='company_fiscal_regime', label='Company Fiscal Regime',
136 fieldtype='Data', insert_after='company_fiscal_code', print_hide=1, read_only=1,
137 fetch_from="company.fiscal_regime"),
138 dict(fieldname='cb_e_invoicing_reference', fieldtype='Column Break',
139 insert_after='company_fiscal_regime', print_hide=1),
140 dict(fieldname='customer_fiscal_code', label='Customer Fiscal Code',
141 fieldtype='Data', insert_after='cb_e_invoicing_reference', read_only=1,
142 fetch_from="customer.fiscal_code"),
143 ],
144 'Purchase Invoice Item': invoice_item_fields,
Gauravf1e28e02019-02-13 16:46:24 +0530145 'Sales Order Item': invoice_item_fields,
146 'Delivery Note Item': invoice_item_fields,
Rohit Waghchaure22ebaf12019-03-07 15:18:49 +0530147 'Sales Invoice Item': invoice_item_fields + customer_po_fields,
Gauravf1e28e02019-02-13 16:46:24 +0530148 'Quotation Item': invoice_item_fields,
149 'Purchase Order Item': invoice_item_fields,
150 'Purchase Receipt Item': invoice_item_fields,
151 'Supplier Quotation Item': invoice_item_fields,
Saurabh9fcfc632019-02-20 13:03:50 +0530152 'Address': [
153 dict(fieldname='country_code', label='Country Code',
Rohit Waghchaure74cfe572019-02-26 20:08:26 +0530154 fieldtype='Data', insert_after='country', print_hide=1, read_only=0,
Saurabh9fcfc632019-02-20 13:03:50 +0530155 fetch_from="country.code"),
156 dict(fieldname='state_code', label='State Code',
157 fieldtype='Data', insert_after='state', print_hide=1)
hello@openetech.com70214022019-10-16 23:38:51 +0530158 ],
159 'Purchase Invoice': [
160 dict(fieldname='document_type', label='Document Type',
161 fieldtype='Data', insert_after='company', print_hide=1, read_only=1
162 ),
163 dict(fieldname='destination_code', label='Destination Code',
164 fieldtype='Data', insert_after='company', print_hide=1, read_only=1
165 ),
166 dict(fieldname='imported_grand_total', label='Imported Grand Total',
167 fieldtype='Data', insert_after='update_auto_repeat_reference', print_hide=1, read_only=1
168 )
169 ],
170 'Purchase Taxes and Charges': [
171 dict(fieldname='tax_rate', label='Tax Rate',
172 fieldtype='Data', insert_after='parenttype', print_hide=1, read_only=0
173 )
174 ],
175 'Supplier': [
176 dict(fieldname='fiscal_code', label='Fiscal Code',
177 fieldtype='Data', insert_after='tax_id', print_hide=1, read_only=1
178 ),
179 dict(fieldname='fiscal_regime', label='Fiscal Regime',
180 fieldtype='Select', insert_after='fiscal_code', print_hide=1, read_only=1,
181 options= "\nRF01\nRF02\nRF04\nRF05\nRF06\nRF07\nRF08\nRF09\nRF10\nRF11\nRF12\nRF13\nRF14\nRF15\nRF16\nRF17\nRF18\nRF19"
182 )
Saurabh9fcfc632019-02-20 13:03:50 +0530183 ]
184 }
Gaurava4aa80f2019-01-06 12:40:28 +0530185
Saurabh9fcfc632019-02-20 13:03:50 +0530186 create_custom_fields(custom_fields, ignore_validate = frappe.flags.in_patch, update=update)
Gauravf1e28e02019-02-13 16:46:24 +0530187
188def setup_report():
Saurabh9fcfc632019-02-20 13:03:50 +0530189 report_name = 'Electronic Invoice Register'
Gauravf1e28e02019-02-13 16:46:24 +0530190
Saurabh9fcfc632019-02-20 13:03:50 +0530191 frappe.db.sql(""" update `tabReport` set disabled = 0 where
192 name = %s """, report_name)
Gauravf1e28e02019-02-13 16:46:24 +0530193
Saurabh9fcfc632019-02-20 13:03:50 +0530194 if not frappe.db.get_value('Custom Role', dict(report=report_name)):
195 frappe.get_doc(dict(
196 doctype='Custom Role',
197 report=report_name,
198 roles= [
199 dict(role='Accounts User'),
200 dict(role='Accounts Manager')
201 ]
202 )).insert()