Merge pull request #26892 from rohitwaghchaure/merged-v13-hotfix-into-pre-release
chore: merge version-13-hotfix into version-13-pre-release
This commit is contained in:
commit
a631ac605f
@ -147,10 +147,15 @@
|
||||
"Chart": true,
|
||||
"Cypress": true,
|
||||
"cy": true,
|
||||
"describe": true,
|
||||
"expect": true,
|
||||
"it": true,
|
||||
"context": true,
|
||||
"before": true,
|
||||
"beforeEach": true,
|
||||
"onScan": true
|
||||
"onScan": true,
|
||||
"html2canvas": true,
|
||||
"extend_cscript": true,
|
||||
"localforage": true
|
||||
}
|
||||
}
|
||||
|
2
.github/helper/install.sh
vendored
2
.github/helper/install.sh
vendored
@ -42,5 +42,5 @@ sed -i 's/socketio:/# socketio:/g' Procfile
|
||||
sed -i 's/redis_socketio:/# redis_socketio:/g' Procfile
|
||||
|
||||
bench get-app erpnext "${GITHUB_WORKSPACE}"
|
||||
bench start &
|
||||
bench start &> bench_run_logs.txt &
|
||||
bench --site test_site reinstall --yes
|
||||
|
108
.github/workflows/ui-tests.yml
vendored
Normal file
108
.github/workflows/ui-tests.yml
vendored
Normal file
@ -0,0 +1,108 @@
|
||||
name: UI
|
||||
|
||||
on:
|
||||
pull_request:
|
||||
workflow_dispatch:
|
||||
|
||||
jobs:
|
||||
test:
|
||||
runs-on: ubuntu-18.04
|
||||
|
||||
strategy:
|
||||
fail-fast: false
|
||||
|
||||
name: UI Tests (Cypress)
|
||||
|
||||
services:
|
||||
mysql:
|
||||
image: mariadb:10.3
|
||||
env:
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: YES
|
||||
ports:
|
||||
- 3306:3306
|
||||
options: --health-cmd="mysqladmin ping" --health-interval=5s --health-timeout=2s --health-retries=3
|
||||
|
||||
steps:
|
||||
- name: Clone
|
||||
uses: actions/checkout@v2
|
||||
|
||||
- name: Setup Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: 3.7
|
||||
|
||||
- uses: actions/setup-node@v2
|
||||
with:
|
||||
node-version: 14
|
||||
check-latest: true
|
||||
|
||||
- name: Add to Hosts
|
||||
run: |
|
||||
echo "127.0.0.1 test_site" | sudo tee -a /etc/hosts
|
||||
|
||||
- name: Cache pip
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.cache/pip
|
||||
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-pip-
|
||||
${{ runner.os }}-
|
||||
|
||||
- name: Cache node modules
|
||||
uses: actions/cache@v2
|
||||
env:
|
||||
cache-name: cache-node-modules
|
||||
with:
|
||||
path: ~/.npm
|
||||
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package-lock.json') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-build-${{ env.cache-name }}-
|
||||
${{ runner.os }}-build-
|
||||
${{ runner.os }}-
|
||||
|
||||
- name: Get yarn cache directory path
|
||||
id: yarn-cache-dir-path
|
||||
run: echo "::set-output name=dir::$(yarn cache dir)"
|
||||
|
||||
- uses: actions/cache@v2
|
||||
id: yarn-cache
|
||||
with:
|
||||
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
|
||||
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
|
||||
restore-keys: |
|
||||
${{ runner.os }}-yarn-
|
||||
|
||||
- name: Cache cypress binary
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/.cache
|
||||
key: ${{ runner.os }}-cypress-
|
||||
restore-keys: |
|
||||
${{ runner.os }}-cypress-
|
||||
${{ runner.os }}-
|
||||
|
||||
- name: Install
|
||||
run: bash ${GITHUB_WORKSPACE}/.github/helper/install.sh
|
||||
env:
|
||||
DB: mariadb
|
||||
TYPE: ui
|
||||
|
||||
- name: Site Setup
|
||||
run: cd ~/frappe-bench/ && bench --site test_site execute erpnext.setup.utils.before_tests
|
||||
|
||||
- name: cypress pre-requisites
|
||||
run: cd ~/frappe-bench/apps/frappe && yarn add cypress-file-upload@^5 --no-lockfile
|
||||
|
||||
|
||||
- name: Build Assets
|
||||
run: cd ~/frappe-bench/ && bench build
|
||||
|
||||
- name: UI Tests
|
||||
run: cd ~/frappe-bench/ && bench --site test_site run-ui-tests erpnext --headless
|
||||
env:
|
||||
CYPRESS_RECORD_KEY: 60a8e3bf-08f5-45b1-9269-2b207d7d30cd
|
||||
|
||||
- name: Show bench console if tests failed
|
||||
if: ${{ failure() }}
|
||||
run: cat ~/frappe-bench/bench_run_logs.txt
|
11
cypress.json
Normal file
11
cypress.json
Normal file
@ -0,0 +1,11 @@
|
||||
{
|
||||
"baseUrl": "http://test_site:8000",
|
||||
"projectId": "da59y9",
|
||||
"adminPassword": "admin",
|
||||
"defaultCommandTimeout": 20000,
|
||||
"pageLoadTimeout": 15000,
|
||||
"retries": {
|
||||
"runMode": 2,
|
||||
"openMode": 2
|
||||
}
|
||||
}
|
5
cypress/fixtures/example.json
Normal file
5
cypress/fixtures/example.json
Normal file
@ -0,0 +1,5 @@
|
||||
{
|
||||
"name": "Using fixtures to represent data",
|
||||
"email": "hello@cypress.io",
|
||||
"body": "Fixtures are a great way to mock data for responses to routes"
|
||||
}
|
13
cypress/integration/test_customer.js
Normal file
13
cypress/integration/test_customer.js
Normal file
@ -0,0 +1,13 @@
|
||||
|
||||
context('Customer', () => {
|
||||
before(() => {
|
||||
cy.login();
|
||||
});
|
||||
it('Check Customer Group', () => {
|
||||
cy.visit(`app/customer/`);
|
||||
cy.get('.primary-action').click();
|
||||
cy.wait(500);
|
||||
cy.get('.custom-actions > .btn').click();
|
||||
cy.get_field('customer_group', 'Link').should('have.value', 'All Customer Groups');
|
||||
});
|
||||
});
|
111
cypress/integration/test_organizational_chart_desktop.js
Normal file
111
cypress/integration/test_organizational_chart_desktop.js
Normal file
@ -0,0 +1,111 @@
|
||||
context('Organizational Chart', () => {
|
||||
before(() => {
|
||||
cy.login();
|
||||
cy.visit('/app/website');
|
||||
cy.awesomebar('Organizational Chart');
|
||||
|
||||
cy.window().its('frappe.csrf_token').then(csrf_token => {
|
||||
return cy.request({
|
||||
url: `/api/method/erpnext.tests.ui_test_helpers.create_employee_records`,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
'X-Frappe-CSRF-Token': csrf_token
|
||||
},
|
||||
timeout: 60000
|
||||
}).then(res => {
|
||||
expect(res.status).eq(200);
|
||||
cy.get('.frappe-control[data-fieldname=company] input').focus().as('input');
|
||||
cy.get('@input')
|
||||
.clear({ force: true })
|
||||
.type('Test Org Chart{enter}', { force: true })
|
||||
.blur({ force: true });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('renders root nodes and loads children for the first expandable node', () => {
|
||||
// check rendered root nodes and the node name, title, connections
|
||||
cy.get('.hierarchy').find('.root-level ul.node-children').children()
|
||||
.should('have.length', 2)
|
||||
.first()
|
||||
.as('first-child');
|
||||
|
||||
cy.get('@first-child').get('.node-name').contains('Test Employee 1');
|
||||
cy.get('@first-child').get('.node-info').find('.node-title').contains('CEO');
|
||||
cy.get('@first-child').get('.node-info').find('.node-connections').contains('· 2 Connections');
|
||||
|
||||
cy.call('erpnext.tests.ui_test_helpers.get_employee_records').then(employee_records => {
|
||||
// children of 1st root visible
|
||||
cy.get(`div[data-parent="${employee_records.message[0]}"]`).as('child-node');
|
||||
cy.get('@child-node')
|
||||
.should('have.length', 1)
|
||||
.should('be.visible');
|
||||
cy.get('@child-node').get('.node-name').contains('Test Employee 3');
|
||||
|
||||
// connectors between first root node and immediate child
|
||||
cy.get(`path[data-parent="${employee_records.message[0]}"]`)
|
||||
.should('be.visible')
|
||||
.invoke('attr', 'data-child')
|
||||
.should('equal', employee_records.message[2]);
|
||||
});
|
||||
});
|
||||
|
||||
it('hides active nodes children and connectors on expanding sibling node', () => {
|
||||
cy.call('erpnext.tests.ui_test_helpers.get_employee_records').then(employee_records => {
|
||||
// click sibling
|
||||
cy.get(`#${employee_records.message[1]}`)
|
||||
.click()
|
||||
.should('have.class', 'active');
|
||||
|
||||
// child nodes and connectors hidden
|
||||
cy.get(`[data-parent="${employee_records.message[0]}"]`).should('not.be.visible');
|
||||
cy.get(`path[data-parent="${employee_records.message[0]}"]`).should('not.be.visible');
|
||||
});
|
||||
});
|
||||
|
||||
it('collapses previous level nodes and refreshes connectors on expanding child node', () => {
|
||||
cy.call('erpnext.tests.ui_test_helpers.get_employee_records').then(employee_records => {
|
||||
// click child node
|
||||
cy.get(`#${employee_records.message[3]}`)
|
||||
.click()
|
||||
.should('have.class', 'active');
|
||||
|
||||
// previous level nodes: parent should be on active-path; other nodes should be collapsed
|
||||
cy.get(`#${employee_records.message[0]}`).should('have.class', 'collapsed');
|
||||
cy.get(`#${employee_records.message[1]}`).should('have.class', 'active-path');
|
||||
|
||||
// previous level connectors refreshed
|
||||
cy.get(`path[data-parent="${employee_records.message[1]}"]`)
|
||||
.should('have.class', 'collapsed-connector');
|
||||
|
||||
// child node's children and connectors rendered
|
||||
cy.get(`[data-parent="${employee_records.message[3]}"]`).should('be.visible');
|
||||
cy.get(`path[data-parent="${employee_records.message[3]}"]`).should('be.visible');
|
||||
});
|
||||
});
|
||||
|
||||
it('expands previous level nodes', () => {
|
||||
cy.call('erpnext.tests.ui_test_helpers.get_employee_records').then(employee_records => {
|
||||
cy.get(`#${employee_records.message[0]}`)
|
||||
.click()
|
||||
.should('have.class', 'active');
|
||||
|
||||
cy.get(`[data-parent="${employee_records.message[0]}"]`)
|
||||
.should('be.visible');
|
||||
|
||||
cy.get('ul.hierarchy').children().should('have.length', 2);
|
||||
cy.get(`#connectors`).children().should('have.length', 1);
|
||||
});
|
||||
});
|
||||
|
||||
it('edit node navigates to employee master', () => {
|
||||
cy.call('erpnext.tests.ui_test_helpers.get_employee_records').then(employee_records => {
|
||||
cy.get(`#${employee_records.message[0]}`).find('.btn-edit-node')
|
||||
.click();
|
||||
|
||||
cy.url().should('include', `/employee/${employee_records.message[0]}`);
|
||||
});
|
||||
});
|
||||
});
|
190
cypress/integration/test_organizational_chart_mobile.js
Normal file
190
cypress/integration/test_organizational_chart_mobile.js
Normal file
@ -0,0 +1,190 @@
|
||||
context('Organizational Chart Mobile', () => {
|
||||
before(() => {
|
||||
cy.login();
|
||||
cy.viewport(375, 667);
|
||||
cy.visit('/app/website');
|
||||
cy.awesomebar('Organizational Chart');
|
||||
|
||||
cy.window().its('frappe.csrf_token').then(csrf_token => {
|
||||
return cy.request({
|
||||
url: `/api/method/erpnext.tests.ui_test_helpers.create_employee_records`,
|
||||
method: 'POST',
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
'X-Frappe-CSRF-Token': csrf_token
|
||||
},
|
||||
timeout: 60000
|
||||
}).then(res => {
|
||||
expect(res.status).eq(200);
|
||||
cy.get('.frappe-control[data-fieldname=company] input').focus().as('input');
|
||||
cy.get('@input')
|
||||
.clear({ force: true })
|
||||
.type('Test Org Chart{enter}', { force: true })
|
||||
.blur({ force: true });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('renders root nodes', () => {
|
||||
// check rendered root nodes and the node name, title, connections
|
||||
cy.get('.hierarchy-mobile').find('.root-level').children()
|
||||
.should('have.length', 2)
|
||||
.first()
|
||||
.as('first-child');
|
||||
|
||||
cy.get('@first-child').get('.node-name').contains('Test Employee 1');
|
||||
cy.get('@first-child').get('.node-info').find('.node-title').contains('CEO');
|
||||
cy.get('@first-child').get('.node-info').find('.node-connections').contains('· 2');
|
||||
});
|
||||
|
||||
it('expands root node', () => {
|
||||
cy.call('erpnext.tests.ui_test_helpers.get_employee_records').then(employee_records => {
|
||||
cy.get(`#${employee_records.message[1]}`)
|
||||
.click()
|
||||
.should('have.class', 'active');
|
||||
|
||||
// other root node removed
|
||||
cy.get(`#${employee_records.message[0]}`).should('not.exist');
|
||||
|
||||
// children of active root node
|
||||
cy.get('.hierarchy-mobile').find('.level').first().find('ul.node-children').children()
|
||||
.should('have.length', 2);
|
||||
|
||||
cy.get(`div[data-parent="${employee_records.message[1]}"]`).first().as('child-node');
|
||||
cy.get('@child-node').should('be.visible');
|
||||
|
||||
cy.get('@child-node')
|
||||
.get('.node-name')
|
||||
.contains('Test Employee 4');
|
||||
|
||||
// connectors between root node and immediate children
|
||||
cy.get(`path[data-parent="${employee_records.message[1]}"]`).as('connectors');
|
||||
cy.get('@connectors')
|
||||
.should('have.length', 2)
|
||||
.should('be.visible');
|
||||
|
||||
cy.get('@connectors')
|
||||
.first()
|
||||
.invoke('attr', 'data-child')
|
||||
.should('eq', employee_records.message[3]);
|
||||
});
|
||||
});
|
||||
|
||||
it('expands child node', () => {
|
||||
cy.call('erpnext.tests.ui_test_helpers.get_employee_records').then(employee_records => {
|
||||
cy.get(`#${employee_records.message[3]}`)
|
||||
.click()
|
||||
.should('have.class', 'active')
|
||||
.as('expanded_node');
|
||||
|
||||
// 2 levels on screen; 1 on active path; 1 collapsed
|
||||
cy.get('.hierarchy-mobile').children().should('have.length', 2);
|
||||
cy.get(`#${employee_records.message[1]}`).should('have.class', 'active-path');
|
||||
|
||||
// children of expanded node visible
|
||||
cy.get('@expanded_node')
|
||||
.next()
|
||||
.should('have.class', 'node-children')
|
||||
.as('node-children');
|
||||
|
||||
cy.get('@node-children').children().should('have.length', 1);
|
||||
cy.get('@node-children')
|
||||
.first()
|
||||
.get('.node-card')
|
||||
.should('have.class', 'active-child')
|
||||
.contains('Test Employee 7');
|
||||
|
||||
// orphan connectors removed
|
||||
cy.get(`#connectors`).children().should('have.length', 2);
|
||||
});
|
||||
});
|
||||
|
||||
it('renders sibling group', () => {
|
||||
cy.call('erpnext.tests.ui_test_helpers.get_employee_records').then(employee_records => {
|
||||
// sibling group visible for parent
|
||||
cy.get(`#${employee_records.message[1]}`)
|
||||
.next()
|
||||
.as('sibling_group');
|
||||
|
||||
cy.get('@sibling_group')
|
||||
.should('have.attr', 'data-parent', 'undefined')
|
||||
.should('have.class', 'node-group')
|
||||
.and('have.class', 'collapsed');
|
||||
|
||||
cy.get('@sibling_group').get('.avatar-group').children().as('siblings');
|
||||
cy.get('@siblings').should('have.length', 1);
|
||||
cy.get('@siblings')
|
||||
.first()
|
||||
.should('have.attr', 'title', 'Test Employee 1');
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
it('expands previous level nodes', () => {
|
||||
cy.call('erpnext.tests.ui_test_helpers.get_employee_records').then(employee_records => {
|
||||
cy.get(`#${employee_records.message[6]}`)
|
||||
.click()
|
||||
.should('have.class', 'active');
|
||||
|
||||
// clicking on previous level node should remove all the nodes ahead
|
||||
// and expand that node
|
||||
cy.get(`#${employee_records.message[3]}`).click();
|
||||
cy.get(`#${employee_records.message[3]}`)
|
||||
.should('have.class', 'active')
|
||||
.should('not.have.class', 'active-path');
|
||||
|
||||
cy.get(`#${employee_records.message[6]}`).should('have.class', 'active-child');
|
||||
cy.get('.hierarchy-mobile').children().should('have.length', 2);
|
||||
cy.get(`#connectors`).children().should('have.length', 2);
|
||||
});
|
||||
});
|
||||
|
||||
it('expands sibling group', () => {
|
||||
cy.call('erpnext.tests.ui_test_helpers.get_employee_records').then(employee_records => {
|
||||
// sibling group visible for parent
|
||||
cy.get(`#${employee_records.message[6]}`).click();
|
||||
|
||||
cy.get(`#${employee_records.message[3]}`)
|
||||
.next()
|
||||
.click();
|
||||
|
||||
// siblings of parent should be visible
|
||||
cy.get('.hierarchy-mobile').prev().as('sibling_group');
|
||||
cy.get('@sibling_group')
|
||||
.should('exist')
|
||||
.should('have.class', 'sibling-group')
|
||||
.should('not.have.class', 'collapsed');
|
||||
|
||||
cy.get(`#${employee_records.message[1]}`)
|
||||
.should('be.visible')
|
||||
.should('have.class', 'active');
|
||||
|
||||
cy.get(`[data-parent="${employee_records.message[1]}"]`)
|
||||
.should('be.visible')
|
||||
.should('have.length', 2)
|
||||
.should('have.class', 'active-child');
|
||||
});
|
||||
});
|
||||
|
||||
it('goes to the respective level after clicking on non-collapsed sibling group', () => {
|
||||
cy.call('erpnext.tests.ui_test_helpers.get_employee_records').then(() => {
|
||||
// click on non-collapsed sibling group
|
||||
cy.get('.hierarchy-mobile')
|
||||
.prev()
|
||||
.click();
|
||||
|
||||
// should take you to that level
|
||||
cy.get('.hierarchy-mobile').find('li.level .node-card').should('have.length', 2);
|
||||
});
|
||||
});
|
||||
|
||||
it('edit node navigates to employee master', () => {
|
||||
cy.call('erpnext.tests.ui_test_helpers.get_employee_records').then(employee_records => {
|
||||
cy.get(`#${employee_records.message[0]}`).find('.btn-edit-node')
|
||||
.click();
|
||||
|
||||
cy.url().should('include', `/employee/${employee_records.message[0]}`);
|
||||
});
|
||||
});
|
||||
});
|
17
cypress/plugins/index.js
Normal file
17
cypress/plugins/index.js
Normal file
@ -0,0 +1,17 @@
|
||||
// ***********************************************************
|
||||
// This example plugins/index.js can be used to load plugins
|
||||
//
|
||||
// You can change the location of this file or turn off loading
|
||||
// the plugins file with the 'pluginsFile' configuration option.
|
||||
//
|
||||
// You can read more here:
|
||||
// https://on.cypress.io/plugins-guide
|
||||
// ***********************************************************
|
||||
|
||||
// This function is called when a project is opened or re-opened (e.g. due to
|
||||
// the project's config changing)
|
||||
|
||||
module.exports = () => {
|
||||
// `on` is used to hook into various events Cypress emits
|
||||
// `config` is the resolved Cypress config
|
||||
};
|
31
cypress/support/commands.js
Normal file
31
cypress/support/commands.js
Normal file
@ -0,0 +1,31 @@
|
||||
// ***********************************************
|
||||
// This example commands.js shows you how to
|
||||
// create various custom commands and overwrite
|
||||
// existing commands.
|
||||
//
|
||||
// For more comprehensive examples of custom
|
||||
// commands please read more here:
|
||||
// https://on.cypress.io/custom-commands
|
||||
// ***********************************************
|
||||
//
|
||||
//
|
||||
// -- This is a parent command --
|
||||
// Cypress.Commands.add("login", (email, password) => { ... });
|
||||
//
|
||||
//
|
||||
// -- This is a child command --
|
||||
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... });
|
||||
//
|
||||
//
|
||||
// -- This is a dual command --
|
||||
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... });
|
||||
//
|
||||
//
|
||||
// -- This is will overwrite an existing command --
|
||||
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... });
|
||||
|
||||
const slug = (name) => name.toLowerCase().replace(" ", "-");
|
||||
|
||||
Cypress.Commands.add("go_to_doc", (doctype, name) => {
|
||||
cy.visit(`/app/${slug(doctype)}/${encodeURIComponent(name)}`);
|
||||
});
|
26
cypress/support/index.js
Normal file
26
cypress/support/index.js
Normal file
@ -0,0 +1,26 @@
|
||||
// ***********************************************************
|
||||
// This example support/index.js is processed and
|
||||
// loaded automatically before your test files.
|
||||
//
|
||||
// This is a great place to put global configuration and
|
||||
// behavior that modifies Cypress.
|
||||
//
|
||||
// You can change the location of this file or turn off
|
||||
// automatically serving support files with the
|
||||
// 'supportFile' configuration option.
|
||||
//
|
||||
// You can read more here:
|
||||
// https://on.cypress.io/configuration
|
||||
// ***********************************************************
|
||||
|
||||
// Import commands.js using ES2015 syntax:
|
||||
import './commands';
|
||||
import '../../../frappe/cypress/support/commands' // eslint-disable-line
|
||||
|
||||
|
||||
// Alternatively you can use CommonJS syntax:
|
||||
// require('./commands')
|
||||
|
||||
Cypress.Cookies.defaults({
|
||||
preserve: 'sid'
|
||||
});
|
12
cypress/tsconfig.json
Normal file
12
cypress/tsconfig.json
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"allowJs": true,
|
||||
"baseUrl": "../node_modules",
|
||||
"types": [
|
||||
"cypress"
|
||||
]
|
||||
},
|
||||
"include": [
|
||||
"**/*.*"
|
||||
]
|
||||
}
|
@ -19,6 +19,7 @@
|
||||
"book_asset_depreciation_entry_automatically",
|
||||
"unlink_advance_payment_on_cancelation_of_order",
|
||||
"post_change_gl_entries",
|
||||
"enable_discount_accounting",
|
||||
"tax_settings_section",
|
||||
"determine_address_tax_category_from",
|
||||
"column_break_19",
|
||||
@ -261,6 +262,13 @@
|
||||
"fieldname": "post_change_gl_entries",
|
||||
"fieldtype": "Check",
|
||||
"label": "Create Ledger Entries for Change Amount"
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
"description": "If enabled, additional ledger entries will be made for discounts in a separate Discount Account",
|
||||
"fieldname": "enable_discount_accounting",
|
||||
"fieldtype": "Check",
|
||||
"label": "Enable Discount Accounting"
|
||||
}
|
||||
],
|
||||
"icon": "icon-cog",
|
||||
@ -268,7 +276,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2021-06-17 20:26:03.721202",
|
||||
"modified": "2021-07-12 18:54:29.084958",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Accounts Settings",
|
||||
|
@ -21,6 +21,7 @@ class AccountsSettings(Document):
|
||||
|
||||
self.validate_stale_days()
|
||||
self.enable_payment_schedule_in_print()
|
||||
self.toggle_discount_accounting_fields()
|
||||
|
||||
def validate_stale_days(self):
|
||||
if not self.allow_stale and cint(self.stale_days) <= 0:
|
||||
@ -33,3 +34,22 @@ class AccountsSettings(Document):
|
||||
for doctype in ("Sales Order", "Sales Invoice", "Purchase Order", "Purchase Invoice"):
|
||||
make_property_setter(doctype, "due_date", "print_hide", show_in_print, "Check", validate_fields_for_doctype=False)
|
||||
make_property_setter(doctype, "payment_schedule", "print_hide", 0 if show_in_print else 1, "Check", validate_fields_for_doctype=False)
|
||||
|
||||
def toggle_discount_accounting_fields(self):
|
||||
enable_discount_accounting = cint(self.enable_discount_accounting)
|
||||
|
||||
for doctype in ["Sales Invoice Item", "Purchase Invoice Item"]:
|
||||
make_property_setter(doctype, "discount_account", "hidden", not(enable_discount_accounting), "Check", validate_fields_for_doctype=False)
|
||||
if enable_discount_accounting:
|
||||
make_property_setter(doctype, "discount_account", "mandatory_depends_on", "eval: doc.discount_amount", "Code", validate_fields_for_doctype=False)
|
||||
else:
|
||||
make_property_setter(doctype, "discount_account", "mandatory_depends_on", "", "Code", validate_fields_for_doctype=False)
|
||||
|
||||
for doctype in ["Sales Invoice", "Purchase Invoice"]:
|
||||
make_property_setter(doctype, "additional_discount_account", "hidden", not(enable_discount_accounting), "Check", validate_fields_for_doctype=False)
|
||||
if enable_discount_accounting:
|
||||
make_property_setter(doctype, "additional_discount_account", "mandatory_depends_on", "eval: doc.discount_amount", "Code", validate_fields_for_doctype=False)
|
||||
else:
|
||||
make_property_setter(doctype, "additional_discount_account", "mandatory_depends_on", "", "Code", validate_fields_for_doctype=False)
|
||||
|
||||
make_property_setter("Item", "default_discount_account", "hidden", not(enable_discount_accounting), "Check", validate_fields_for_doctype=False)
|
0
erpnext/accounts/doctype/campaign_item/__init__.py
Normal file
0
erpnext/accounts/doctype/campaign_item/__init__.py
Normal file
31
erpnext/accounts/doctype/campaign_item/campaign_item.json
Normal file
31
erpnext/accounts/doctype/campaign_item/campaign_item.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-05-06 16:18:25.410476",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"campaign"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "campaign",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Campaign",
|
||||
"options": "Campaign"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-05-07 10:43:49.717633",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Campaign Item",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
8
erpnext/accounts/doctype/campaign_item/campaign_item.py
Normal file
8
erpnext/accounts/doctype/campaign_item/campaign_item.py
Normal file
@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class CampaignItem(Document):
|
||||
pass
|
@ -57,7 +57,7 @@ def test_create_test_data():
|
||||
})
|
||||
item_price.insert()
|
||||
# create test item pricing rule
|
||||
if not frappe.db.exists("Pricing Rule","_Test Pricing Rule for _Test Item"):
|
||||
if not frappe.db.exists("Pricing Rule", {"title": "_Test Pricing Rule for _Test Item"}):
|
||||
item_pricing_rule = frappe.get_doc({
|
||||
"doctype": "Pricing Rule",
|
||||
"title": "_Test Pricing Rule for _Test Item",
|
||||
@ -86,14 +86,15 @@ def test_create_test_data():
|
||||
sales_partner.insert()
|
||||
# create test item coupon code
|
||||
if not frappe.db.exists("Coupon Code", "SAVE30"):
|
||||
pricing_rule = frappe.db.get_value("Pricing Rule", {"title": "_Test Pricing Rule for _Test Item"}, ['name'])
|
||||
coupon_code = frappe.get_doc({
|
||||
"doctype": "Coupon Code",
|
||||
"coupon_name":"SAVE30",
|
||||
"coupon_code":"SAVE30",
|
||||
"pricing_rule": "_Test Pricing Rule for _Test Item",
|
||||
"valid_from": "2014-01-01",
|
||||
"maximum_use":1,
|
||||
"used":0
|
||||
"doctype": "Coupon Code",
|
||||
"coupon_name":"SAVE30",
|
||||
"coupon_code":"SAVE30",
|
||||
"pricing_rule": pricing_rule,
|
||||
"valid_from": "2014-01-01",
|
||||
"maximum_use":1,
|
||||
"used":0
|
||||
})
|
||||
coupon_code.insert()
|
||||
|
||||
@ -102,7 +103,7 @@ class TestCouponCode(unittest.TestCase):
|
||||
test_create_test_data()
|
||||
|
||||
def tearDown(self):
|
||||
frappe.set_user("Administrator")
|
||||
frappe.set_user("Administrator")
|
||||
|
||||
def test_sales_order_with_coupon_code(self):
|
||||
frappe.db.set_value("Coupon Code", "SAVE30", "used", 0)
|
||||
|
@ -0,0 +1,31 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-05-06 16:12:42.558878",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"customer_group"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "customer_group",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Customer Group",
|
||||
"options": "Customer Group"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-05-07 10:39:21.563506",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Customer Group Item",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class CustomerGroupItem(Document):
|
||||
pass
|
0
erpnext/accounts/doctype/customer_item/__init__.py
Normal file
0
erpnext/accounts/doctype/customer_item/__init__.py
Normal file
31
erpnext/accounts/doctype/customer_item/customer_item.json
Normal file
31
erpnext/accounts/doctype/customer_item/customer_item.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-05-05 14:04:54.266353",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"customer"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "customer",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Customer ",
|
||||
"options": "Customer"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-05-06 10:02:32.967841",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Customer Item",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
8
erpnext/accounts/doctype/customer_item/customer_item.py
Normal file
8
erpnext/accounts/doctype/customer_item/customer_item.py
Normal file
@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class CustomerItem(Document):
|
||||
pass
|
@ -2,12 +2,13 @@
|
||||
"actions": [],
|
||||
"allow_import": 1,
|
||||
"allow_rename": 1,
|
||||
"autoname": "field:title",
|
||||
"autoname": "naming_series:",
|
||||
"creation": "2014-02-21 15:02:51",
|
||||
"doctype": "DocType",
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"applicability_section",
|
||||
"naming_series",
|
||||
"title",
|
||||
"disable",
|
||||
"apply_on",
|
||||
@ -95,8 +96,7 @@
|
||||
"fieldtype": "Data",
|
||||
"label": "Title",
|
||||
"no_copy": 1,
|
||||
"reqd": 1,
|
||||
"unique": 1
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"default": "0",
|
||||
@ -571,6 +571,13 @@
|
||||
"fieldname": "is_recursive",
|
||||
"fieldtype": "Check",
|
||||
"label": "Is Recursive"
|
||||
},
|
||||
{
|
||||
"default": "PRLE-.####",
|
||||
"fieldname": "naming_series",
|
||||
"fieldtype": "Select",
|
||||
"label": "Naming Series",
|
||||
"options": "PRLE-.####"
|
||||
}
|
||||
],
|
||||
"icon": "fa fa-gift",
|
||||
@ -634,5 +641,6 @@
|
||||
],
|
||||
"show_name_in_global_search": 1,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC"
|
||||
}
|
||||
"sort_order": "DESC",
|
||||
"title_field": "title"
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -25,22 +25,31 @@ product_discount_fields = ['free_item', 'free_qty', 'free_item_uom',
|
||||
|
||||
class PromotionalScheme(Document):
|
||||
def validate(self):
|
||||
if not self.selling and not self.buying:
|
||||
frappe.throw(_("Either 'Selling' or 'Buying' must be selected"), title=_("Mandatory"))
|
||||
if not (self.price_discount_slabs
|
||||
or self.product_discount_slabs):
|
||||
frappe.throw(_("Price or product discount slabs are required"))
|
||||
|
||||
def on_update(self):
|
||||
data = frappe.get_all('Pricing Rule', fields = ["promotional_scheme_id", "name"],
|
||||
filters = {'promotional_scheme': self.name}) or {}
|
||||
pricing_rules = frappe.get_all(
|
||||
'Pricing Rule',
|
||||
fields = ["promotional_scheme_id", "name", "creation"],
|
||||
filters = {
|
||||
'promotional_scheme': self.name,
|
||||
'applicable_for': self.applicable_for
|
||||
},
|
||||
order_by = 'creation asc',
|
||||
) or {}
|
||||
self.update_pricing_rules(pricing_rules)
|
||||
|
||||
self.update_pricing_rules(data)
|
||||
|
||||
def update_pricing_rules(self, data):
|
||||
def update_pricing_rules(self, pricing_rules):
|
||||
rules = {}
|
||||
count = 0
|
||||
|
||||
for d in data:
|
||||
rules[d.get('promotional_scheme_id')] = d.get('name')
|
||||
names = []
|
||||
for rule in pricing_rules:
|
||||
names.append(rule.name)
|
||||
rules[rule.get('promotional_scheme_id')] = names
|
||||
|
||||
docs = get_pricing_rules(self, rules)
|
||||
|
||||
@ -57,9 +66,9 @@ class PromotionalScheme(Document):
|
||||
frappe.msgprint(_("New {0} pricing rules are created").format(count))
|
||||
|
||||
def on_trash(self):
|
||||
for d in frappe.get_all('Pricing Rule',
|
||||
for rule in frappe.get_all('Pricing Rule',
|
||||
{'promotional_scheme': self.name}):
|
||||
frappe.delete_doc('Pricing Rule', d.name)
|
||||
frappe.delete_doc('Pricing Rule', rule.name)
|
||||
|
||||
def get_pricing_rules(doc, rules = {}):
|
||||
new_doc = []
|
||||
@ -73,42 +82,80 @@ def get_pricing_rules(doc, rules = {}):
|
||||
def _get_pricing_rules(doc, child_doc, discount_fields, rules = {}):
|
||||
new_doc = []
|
||||
args = get_args_for_pricing_rule(doc)
|
||||
for d in doc.get(child_doc):
|
||||
applicable_for = frappe.scrub(doc.get('applicable_for'))
|
||||
for idx, d in enumerate(doc.get(child_doc)):
|
||||
if d.name in rules:
|
||||
pr = frappe.get_doc('Pricing Rule', rules.get(d.name))
|
||||
for applicable_for_value in args.get(applicable_for):
|
||||
temp_args = args.copy()
|
||||
docname = frappe.get_all(
|
||||
'Pricing Rule',
|
||||
fields = ["promotional_scheme_id", "name", applicable_for],
|
||||
filters = {
|
||||
'promotional_scheme_id': d.name,
|
||||
applicable_for: applicable_for_value
|
||||
}
|
||||
)
|
||||
|
||||
if docname:
|
||||
pr = frappe.get_doc('Pricing Rule', docname[0].get('name'))
|
||||
temp_args[applicable_for] = applicable_for_value
|
||||
pr = set_args(temp_args, pr, doc, child_doc, discount_fields, d)
|
||||
else:
|
||||
pr = frappe.new_doc("Pricing Rule")
|
||||
pr.title = doc.name
|
||||
temp_args[applicable_for] = applicable_for_value
|
||||
pr = set_args(temp_args, pr, doc, child_doc, discount_fields, d)
|
||||
|
||||
new_doc.append(pr)
|
||||
|
||||
else:
|
||||
pr = frappe.new_doc("Pricing Rule")
|
||||
pr.title = make_autoname("{0}/.####".format(doc.name))
|
||||
|
||||
pr.update(args)
|
||||
for field in (other_fields + discount_fields):
|
||||
pr.set(field, d.get(field))
|
||||
|
||||
pr.promotional_scheme_id = d.name
|
||||
pr.promotional_scheme = doc.name
|
||||
pr.disable = d.disable if d.disable else doc.disable
|
||||
pr.price_or_product_discount = ('Price'
|
||||
if child_doc == 'price_discount_slabs' else 'Product')
|
||||
|
||||
for field in ['items', 'item_groups', 'brands']:
|
||||
if doc.get(field):
|
||||
pr.set(field, [])
|
||||
|
||||
apply_on = frappe.scrub(doc.get('apply_on'))
|
||||
for d in doc.get(field):
|
||||
pr.append(field, {
|
||||
apply_on: d.get(apply_on),
|
||||
'uom': d.uom
|
||||
})
|
||||
|
||||
new_doc.append(pr)
|
||||
applicable_for_values = args.get(applicable_for) or []
|
||||
for applicable_for_value in applicable_for_values:
|
||||
pr = frappe.new_doc("Pricing Rule")
|
||||
pr.title = doc.name
|
||||
temp_args = args.copy()
|
||||
temp_args[applicable_for] = applicable_for_value
|
||||
pr = set_args(temp_args, pr, doc, child_doc, discount_fields, d)
|
||||
new_doc.append(pr)
|
||||
|
||||
return new_doc
|
||||
|
||||
|
||||
|
||||
|
||||
def set_args(args, pr, doc, child_doc, discount_fields, child_doc_fields):
|
||||
pr.update(args)
|
||||
for field in (other_fields + discount_fields):
|
||||
pr.set(field, child_doc_fields.get(field))
|
||||
|
||||
pr.promotional_scheme_id = child_doc_fields.name
|
||||
pr.promotional_scheme = doc.name
|
||||
pr.disable = child_doc_fields.disable if child_doc_fields.disable else doc.disable
|
||||
pr.price_or_product_discount = ('Price'
|
||||
if child_doc == 'price_discount_slabs' else 'Product')
|
||||
|
||||
for field in ['items', 'item_groups', 'brands']:
|
||||
if doc.get(field):
|
||||
pr.set(field, [])
|
||||
|
||||
apply_on = frappe.scrub(doc.get('apply_on'))
|
||||
for d in doc.get(field):
|
||||
pr.append(field, {
|
||||
apply_on: d.get(apply_on),
|
||||
'uom': d.uom
|
||||
})
|
||||
return pr
|
||||
|
||||
def get_args_for_pricing_rule(doc):
|
||||
args = { 'promotional_scheme': doc.name }
|
||||
applicable_for = frappe.scrub(doc.get('applicable_for'))
|
||||
|
||||
for d in pricing_rule_fields:
|
||||
args[d] = doc.get(d)
|
||||
|
||||
if d == applicable_for:
|
||||
items = []
|
||||
for applicable_for_values in doc.get(applicable_for):
|
||||
items.append(applicable_for_values.get(applicable_for))
|
||||
args[d] = items
|
||||
else:
|
||||
args[d] = doc.get(d)
|
||||
return args
|
||||
|
@ -7,4 +7,54 @@ import frappe
|
||||
import unittest
|
||||
|
||||
class TestPromotionalScheme(unittest.TestCase):
|
||||
pass
|
||||
def test_promotional_scheme(self):
|
||||
ps = make_promotional_scheme()
|
||||
price_rules = frappe.get_all('Pricing Rule', fields = ["promotional_scheme_id", "name", "creation"],
|
||||
filters = {'promotional_scheme': ps.name})
|
||||
self.assertTrue(len(price_rules),1)
|
||||
price_doc_details = frappe.db.get_value('Pricing Rule', price_rules[0].name, ['customer', 'min_qty', 'discount_percentage'], as_dict = 1)
|
||||
self.assertTrue(price_doc_details.customer, '_Test Customer')
|
||||
self.assertTrue(price_doc_details.min_qty, 4)
|
||||
self.assertTrue(price_doc_details.discount_percentage, 20)
|
||||
|
||||
ps.price_discount_slabs[0].min_qty = 6
|
||||
ps.append('customer', {
|
||||
'customer': "_Test Customer 2"})
|
||||
ps.save()
|
||||
price_rules = frappe.get_all('Pricing Rule', fields = ["promotional_scheme_id", "name"],
|
||||
filters = {'promotional_scheme': ps.name})
|
||||
self.assertTrue(len(price_rules), 2)
|
||||
|
||||
price_doc_details = frappe.db.get_value('Pricing Rule', price_rules[1].name, ['customer', 'min_qty', 'discount_percentage'], as_dict = 1)
|
||||
self.assertTrue(price_doc_details.customer, '_Test Customer 2')
|
||||
self.assertTrue(price_doc_details.min_qty, 6)
|
||||
self.assertTrue(price_doc_details.discount_percentage, 20)
|
||||
|
||||
price_doc_details = frappe.db.get_value('Pricing Rule', price_rules[0].name, ['customer', 'min_qty', 'discount_percentage'], as_dict = 1)
|
||||
self.assertTrue(price_doc_details.customer, '_Test Customer')
|
||||
self.assertTrue(price_doc_details.min_qty, 6)
|
||||
|
||||
frappe.delete_doc('Promotional Scheme', ps.name)
|
||||
price_rules = frappe.get_all('Pricing Rule', fields = ["promotional_scheme_id", "name"],
|
||||
filters = {'promotional_scheme': ps.name})
|
||||
self.assertEqual(price_rules, [])
|
||||
|
||||
def make_promotional_scheme():
|
||||
ps = frappe.new_doc('Promotional Scheme')
|
||||
ps.name = '_Test Scheme'
|
||||
ps.append('items',{
|
||||
'item_code': '_Test Item'
|
||||
})
|
||||
ps.selling = 1
|
||||
ps.append('price_discount_slabs',{
|
||||
'min_qty': 4,
|
||||
'discount_percentage': 20,
|
||||
'rule_description': 'Test'
|
||||
})
|
||||
ps.applicable_for = 'Customer'
|
||||
ps.append('customer',{
|
||||
'customer': "_Test Customer"
|
||||
})
|
||||
ps.save()
|
||||
|
||||
return ps
|
@ -275,7 +275,7 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
|
||||
// Do not update if inter company reference is there as the details will already be updated
|
||||
if(this.frm.updating_party_details || this.frm.doc.inter_company_invoice_reference)
|
||||
return;
|
||||
|
||||
|
||||
erpnext.utils.get_party_details(this.frm, "erpnext.accounts.party.get_party_details",
|
||||
{
|
||||
posting_date: this.frm.doc.posting_date,
|
||||
@ -283,7 +283,8 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
|
||||
party: this.frm.doc.supplier,
|
||||
party_type: "Supplier",
|
||||
account: this.frm.doc.credit_to,
|
||||
price_list: this.frm.doc.buying_price_list
|
||||
price_list: this.frm.doc.buying_price_list,
|
||||
fetch_payment_terms_template: cint(!this.frm.doc.ignore_default_payment_terms_template)
|
||||
}, function() {
|
||||
me.apply_pricing_rule();
|
||||
me.frm.doc.apply_tds = me.frm.supplier_tds ? 1 : 0;
|
||||
@ -365,7 +366,7 @@ erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
|
||||
items_add: function(doc, cdt, cdn) {
|
||||
var row = frappe.get_doc(cdt, cdn);
|
||||
this.frm.script_manager.copy_from_first_row("items", row,
|
||||
["expense_account", "cost_center", "project"]);
|
||||
["expense_account", "discount_account", "cost_center", "project"]);
|
||||
},
|
||||
|
||||
on_submit: function() {
|
||||
@ -499,6 +500,16 @@ frappe.ui.form.on("Purchase Invoice", {
|
||||
'Payment Entry': 'Payment'
|
||||
}
|
||||
|
||||
frm.set_query("additional_discount_account", function() {
|
||||
return {
|
||||
filters: {
|
||||
company: frm.doc.company,
|
||||
is_group: 0,
|
||||
report_type: "Profit and Loss",
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
frm.fields_dict['items'].grid.get_field('deferred_expense_account').get_query = function(doc) {
|
||||
return {
|
||||
filters: {
|
||||
@ -508,6 +519,16 @@ frappe.ui.form.on("Purchase Invoice", {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
frm.fields_dict['items'].grid.get_field('discount_account').get_query = function(doc) {
|
||||
return {
|
||||
filters: {
|
||||
'report_type': 'Profit and Loss',
|
||||
'company': doc.company,
|
||||
"is_group": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
refresh: function(frm) {
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -22,7 +22,7 @@ from erpnext.assets.doctype.asset.asset import get_asset_account, is_cwip_accoun
|
||||
from frappe.model.mapper import get_mapped_doc
|
||||
from six import iteritems
|
||||
from erpnext.accounts.doctype.sales_invoice.sales_invoice import validate_inter_company_party, update_linked_doc,\
|
||||
unlink_inter_company_doc
|
||||
unlink_inter_company_doc, check_if_return_invoice_linked_with_payment_entry
|
||||
from erpnext.accounts.doctype.tax_withholding_category.tax_withholding_category import get_party_tax_withholding_details
|
||||
from erpnext.accounts.deferred_revenue import validate_service_stop_date
|
||||
from erpnext.stock.doctype.purchase_receipt.purchase_receipt import get_item_account_wise_additional_cost
|
||||
@ -446,6 +446,7 @@ class PurchaseInvoice(BuyingController):
|
||||
|
||||
self.make_supplier_gl_entry(gl_entries)
|
||||
self.make_item_gl_entries(gl_entries)
|
||||
self.make_discount_gl_entries(gl_entries)
|
||||
|
||||
if self.check_asset_cwip_enabled():
|
||||
self.get_asset_gl_entry(gl_entries)
|
||||
@ -518,6 +519,8 @@ class PurchaseInvoice(BuyingController):
|
||||
if d.category in ('Valuation', 'Total and Valuation')
|
||||
and flt(d.base_tax_amount_after_discount_amount)]
|
||||
|
||||
enable_discount_accounting = cint(frappe.db.get_single_value('Accounts Settings', 'enable_discount_accounting'))
|
||||
|
||||
for item in self.get("items"):
|
||||
if flt(item.base_net_amount):
|
||||
account_currency = get_account_currency(item.expense_account)
|
||||
@ -608,7 +611,7 @@ class PurchaseInvoice(BuyingController):
|
||||
if (not item.enable_deferred_expense or self.is_return) else item.deferred_expense_account)
|
||||
|
||||
if not item.is_fixed_asset:
|
||||
amount = flt(item.base_net_amount, item.precision("base_net_amount"))
|
||||
dummy, amount = self.get_amount_and_base_amount(item, enable_discount_accounting)
|
||||
else:
|
||||
amount = flt(item.base_net_amount + item.item_tax_amount, item.precision("base_net_amount"))
|
||||
|
||||
@ -822,8 +825,11 @@ class PurchaseInvoice(BuyingController):
|
||||
def make_tax_gl_entries(self, gl_entries):
|
||||
# tax table gl entries
|
||||
valuation_tax = {}
|
||||
enable_discount_accounting = cint(frappe.db.get_single_value('Accounts Settings', 'enable_discount_accounting'))
|
||||
|
||||
for tax in self.get("taxes"):
|
||||
if tax.category in ("Total", "Valuation and Total") and flt(tax.base_tax_amount_after_discount_amount):
|
||||
amount, base_amount = self.get_tax_amounts(tax, enable_discount_accounting)
|
||||
if tax.category in ("Total", "Valuation and Total") and flt(base_amount):
|
||||
account_currency = get_account_currency(tax.account_head)
|
||||
|
||||
dr_or_cr = "debit" if tax.add_deduct_tax == "Add" else "credit"
|
||||
@ -832,21 +838,21 @@ class PurchaseInvoice(BuyingController):
|
||||
self.get_gl_dict({
|
||||
"account": tax.account_head,
|
||||
"against": self.supplier,
|
||||
dr_or_cr: tax.base_tax_amount_after_discount_amount,
|
||||
dr_or_cr + "_in_account_currency": tax.base_tax_amount_after_discount_amount \
|
||||
if account_currency==self.company_currency \
|
||||
else tax.tax_amount_after_discount_amount,
|
||||
dr_or_cr: base_amount,
|
||||
dr_or_cr + "_in_account_currency": base_amount
|
||||
if account_currency==self.company_currency
|
||||
else amount,
|
||||
"cost_center": tax.cost_center
|
||||
}, account_currency, item=tax)
|
||||
)
|
||||
# accumulate valuation tax
|
||||
if self.is_opening == "No" and tax.category in ("Valuation", "Valuation and Total") and flt(tax.base_tax_amount_after_discount_amount) \
|
||||
if self.is_opening == "No" and tax.category in ("Valuation", "Valuation and Total") and flt(base_amount) \
|
||||
and not self.is_internal_transfer():
|
||||
if self.auto_accounting_for_stock and not tax.cost_center:
|
||||
frappe.throw(_("Cost Center is required in row {0} in Taxes table for type {1}").format(tax.idx, _(tax.category)))
|
||||
valuation_tax.setdefault(tax.name, 0)
|
||||
valuation_tax[tax.name] += \
|
||||
(tax.add_deduct_tax == "Add" and 1 or -1) * flt(tax.base_tax_amount_after_discount_amount)
|
||||
(tax.add_deduct_tax == "Add" and 1 or -1) * flt(base_amount)
|
||||
|
||||
if self.is_opening == "No" and self.negative_expense_to_be_booked and valuation_tax:
|
||||
# credit valuation tax amount in "Expenses Included In Valuation"
|
||||
@ -982,6 +988,8 @@ class PurchaseInvoice(BuyingController):
|
||||
}, item=self))
|
||||
|
||||
def on_cancel(self):
|
||||
check_if_return_invoice_linked_with_payment_entry(self)
|
||||
|
||||
super(PurchaseInvoice, self).on_cancel()
|
||||
|
||||
self.check_on_hold_or_closed_status()
|
||||
|
@ -230,6 +230,50 @@ class TestPurchaseInvoice(unittest.TestCase):
|
||||
self.assertEqual(expected_values[gle.account][1], gle.debit)
|
||||
self.assertEqual(expected_values[gle.account][2], gle.credit)
|
||||
|
||||
def test_purchase_invoice_with_discount_accounting_enabled(self):
|
||||
enable_discount_accounting()
|
||||
|
||||
discount_account = create_account(account_name="Discount Account",
|
||||
parent_account="Indirect Expenses - _TC", company="_Test Company")
|
||||
pi = make_purchase_invoice(discount_account=discount_account, rate=45)
|
||||
|
||||
expected_gle = [
|
||||
["_Test Account Cost for Goods Sold - _TC", 250.0, 0.0, nowdate()],
|
||||
["Creditors - _TC", 0.0, 225.0, nowdate()],
|
||||
["Discount Account - _TC", 0.0, 25.0, nowdate()]
|
||||
]
|
||||
|
||||
check_gl_entries(self, pi.name, expected_gle, nowdate())
|
||||
enable_discount_accounting(enable=0)
|
||||
|
||||
def test_additional_discount_for_purchase_invoice_with_discount_accounting_enabled(self):
|
||||
enable_discount_accounting()
|
||||
additional_discount_account = create_account(account_name="Discount Account",
|
||||
parent_account="Indirect Expenses - _TC", company="_Test Company")
|
||||
|
||||
pi = make_purchase_invoice(do_not_save=1, parent_cost_center="Main - _TC")
|
||||
pi.apply_discount_on = "Grand Total"
|
||||
pi.additional_discount_account = additional_discount_account
|
||||
pi.additional_discount_percentage = 10
|
||||
pi.disable_rounded_total = 1
|
||||
pi.append("taxes", {
|
||||
"charge_type": "On Net Total",
|
||||
"account_head": "_Test Account VAT - _TC",
|
||||
"cost_center": "Main - _TC",
|
||||
"description": "Test",
|
||||
"rate": 10
|
||||
})
|
||||
pi.submit()
|
||||
|
||||
expected_gle = [
|
||||
["_Test Account Cost for Goods Sold - _TC", 250.0, 0.0, nowdate()],
|
||||
["_Test Account VAT - _TC", 25.0, 0.0, nowdate()],
|
||||
["Creditors - _TC", 0.0, 247.5, nowdate()],
|
||||
["Discount Account - _TC", 0.0, 27.5, nowdate()]
|
||||
]
|
||||
|
||||
check_gl_entries(self, pi.name, expected_gle, nowdate())
|
||||
|
||||
def test_purchase_invoice_change_naming_series(self):
|
||||
pi = frappe.copy_doc(test_records[1])
|
||||
pi.insert()
|
||||
@ -1140,6 +1184,18 @@ class TestPurchaseInvoice(unittest.TestCase):
|
||||
self.assertEqual(expected_gle[i][0], gle.account)
|
||||
self.assertEqual(expected_gle[i][1], gle.amount)
|
||||
|
||||
def check_gl_entries(doc, voucher_no, expected_gle, posting_date):
|
||||
gl_entries = frappe.db.sql("""select account, debit, credit, posting_date
|
||||
from `tabGL Entry`
|
||||
where voucher_type='Purchase Invoice' and voucher_no=%s and posting_date >= %s
|
||||
order by posting_date asc, account asc""", (voucher_no, posting_date), as_dict=1)
|
||||
|
||||
for i, gle in enumerate(gl_entries):
|
||||
doc.assertEqual(expected_gle[i][0], gle.account)
|
||||
doc.assertEqual(expected_gle[i][1], gle.debit)
|
||||
doc.assertEqual(expected_gle[i][2], gle.credit)
|
||||
doc.assertEqual(getdate(expected_gle[i][3]), gle.posting_date)
|
||||
|
||||
def update_tax_witholding_category(company, account, date):
|
||||
from erpnext.accounts.utils import get_fiscal_year
|
||||
|
||||
@ -1170,6 +1226,11 @@ def unlink_payment_on_cancel_of_invoice(enable=1):
|
||||
accounts_settings.unlink_payment_on_cancellation_of_invoice = enable
|
||||
accounts_settings.save()
|
||||
|
||||
def enable_discount_accounting(enable=1):
|
||||
accounts_settings = frappe.get_doc("Accounts Settings")
|
||||
accounts_settings.enable_discount_accounting = enable
|
||||
accounts_settings.save()
|
||||
|
||||
def make_purchase_invoice(**args):
|
||||
pi = frappe.new_doc("Purchase Invoice")
|
||||
args = frappe._dict(args)
|
||||
@ -1192,6 +1253,7 @@ def make_purchase_invoice(**args):
|
||||
pi.return_against = args.return_against
|
||||
pi.is_subcontracted = args.is_subcontracted or "No"
|
||||
pi.supplier_warehouse = args.supplier_warehouse or "_Test Warehouse 1 - _TC"
|
||||
pi.cost_center = args.parent_cost_center
|
||||
|
||||
pi.append("items", {
|
||||
"item_code": args.item or args.item_code or "_Test Item",
|
||||
@ -1200,7 +1262,10 @@ def make_purchase_invoice(**args):
|
||||
"received_qty": args.received_qty or 0,
|
||||
"rejected_qty": args.rejected_qty or 0,
|
||||
"rate": args.rate or 50,
|
||||
'expense_account': args.expense_account or '_Test Account Cost for Goods Sold - _TC',
|
||||
"price_list_rate": args.price_list_rate or 50,
|
||||
"expense_account": args.expense_account or '_Test Account Cost for Goods Sold - _TC',
|
||||
"discount_account": args.discount_account or None,
|
||||
"discount_amount": args.discount_amount or 0,
|
||||
"conversion_factor": 1.0,
|
||||
"serial_no": args.serial_no,
|
||||
"stock_uom": args.uom or "_Test UOM",
|
||||
|
@ -73,6 +73,7 @@
|
||||
"manufacturer_part_no",
|
||||
"accounting",
|
||||
"expense_account",
|
||||
"discount_account",
|
||||
"col_break5",
|
||||
"is_fixed_asset",
|
||||
"asset_location",
|
||||
@ -849,12 +850,18 @@
|
||||
"options": "Company:company:default_currency",
|
||||
"print_hide": 1,
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "discount_account",
|
||||
"fieldtype": "Link",
|
||||
"label": "Discount Account",
|
||||
"options": "Account"
|
||||
}
|
||||
],
|
||||
"idx": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-06-16 19:57:03.101571",
|
||||
"modified": "2021-07-13 02:04:37.787882",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Purchase Invoice Item",
|
||||
|
@ -347,7 +347,7 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
|
||||
|
||||
items_add: function(doc, cdt, cdn) {
|
||||
var row = frappe.get_doc(cdt, cdn);
|
||||
this.frm.script_manager.copy_from_first_row("items", row, ["income_account", "cost_center"]);
|
||||
this.frm.script_manager.copy_from_first_row("items", row, ["income_account", "discount_account", "cost_center"]);
|
||||
},
|
||||
|
||||
set_dynamic_labels: function() {
|
||||
@ -447,6 +447,15 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte
|
||||
this.frm.refresh_field("outstanding_amount");
|
||||
this.frm.refresh_field("paid_amount");
|
||||
this.frm.refresh_field("base_paid_amount");
|
||||
},
|
||||
|
||||
currency() {
|
||||
this._super();
|
||||
$.each(cur_frm.doc.timesheets, function(i, d) {
|
||||
let row = frappe.get_doc(d.doctype, d.name)
|
||||
set_timesheet_detail_rate(row.doctype, row.name, cur_frm.doc.currency, row.timesheet_detail)
|
||||
});
|
||||
calculate_total_billing_amount(cur_frm)
|
||||
}
|
||||
});
|
||||
|
||||
@ -510,7 +519,6 @@ cur_frm.set_query("income_account", "items", function(doc) {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Cost Center in Details Table
|
||||
// -----------------------------
|
||||
cur_frm.fields_dict["items"].grid.get_field("cost_center").get_query = function(doc) {
|
||||
@ -592,6 +600,16 @@ frappe.ui.form.on('Sales Invoice', {
|
||||
};
|
||||
});
|
||||
|
||||
frm.set_query("additional_discount_account", function() {
|
||||
return {
|
||||
filters: {
|
||||
company: frm.doc.company,
|
||||
is_group: 0,
|
||||
report_type: "Profit and Loss",
|
||||
}
|
||||
};
|
||||
});
|
||||
|
||||
frm.custom_make_buttons = {
|
||||
'Delivery Note': 'Delivery',
|
||||
'Sales Invoice': 'Return / Credit Note',
|
||||
@ -618,6 +636,17 @@ frappe.ui.form.on('Sales Invoice', {
|
||||
}
|
||||
}
|
||||
|
||||
// discount account
|
||||
frm.fields_dict['items'].grid.get_field('discount_account').get_query = function(doc) {
|
||||
return {
|
||||
filters: {
|
||||
'report_type': 'Profit and Loss',
|
||||
'company': doc.company,
|
||||
"is_group": 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
frm.fields_dict['items'].grid.get_field('deferred_revenue_account').get_query = function(doc) {
|
||||
return {
|
||||
filters: {
|
||||
@ -826,7 +855,8 @@ frappe.ui.form.on('Sales Invoice', {
|
||||
'time_sheet': row.parent,
|
||||
'billing_hours': row.billing_hours,
|
||||
'billing_amount': flt(row.billing_amount) * flt(exchange_rate),
|
||||
'timesheet_detail': row.name
|
||||
'timesheet_detail': row.name,
|
||||
'project_name': row.project_name
|
||||
});
|
||||
frm.refresh_field('timesheets');
|
||||
calculate_total_billing_amount(frm);
|
||||
@ -945,43 +975,34 @@ frappe.ui.form.on('Sales Invoice', {
|
||||
}
|
||||
})
|
||||
|
||||
frappe.ui.form.on('Sales Invoice Timesheet', {
|
||||
time_sheet: function(frm, cdt, cdn){
|
||||
var d = locals[cdt][cdn];
|
||||
if(d.time_sheet) {
|
||||
frappe.call({
|
||||
method: "erpnext.projects.doctype.timesheet.timesheet.get_timesheet_data",
|
||||
args: {
|
||||
'name': d.time_sheet,
|
||||
'project': frm.doc.project || null
|
||||
},
|
||||
callback: function(r, rt) {
|
||||
if(r.message){
|
||||
let data = r.message;
|
||||
frappe.model.set_value(cdt, cdn, "billing_hours", data.billing_hours);
|
||||
frappe.model.set_value(cdt, cdn, "billing_amount", data.billing_amount);
|
||||
frappe.model.set_value(cdt, cdn, "timesheet_detail", data.timesheet_detail);
|
||||
calculate_total_billing_amount(frm)
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
var calculate_total_billing_amount = function(frm) {
|
||||
var doc = frm.doc;
|
||||
|
||||
doc.total_billing_amount = 0.0
|
||||
if(doc.timesheets) {
|
||||
if (doc.timesheets) {
|
||||
$.each(doc.timesheets, function(index, data){
|
||||
doc.total_billing_amount += data.billing_amount
|
||||
doc.total_billing_amount += flt(data.billing_amount)
|
||||
})
|
||||
}
|
||||
|
||||
refresh_field('total_billing_amount')
|
||||
}
|
||||
|
||||
var set_timesheet_detail_rate = function(cdt, cdn, currency, timelog) {
|
||||
frappe.call({
|
||||
method: "erpnext.projects.doctype.timesheet.timesheet.get_timesheet_detail_rate",
|
||||
args: {
|
||||
timelog: timelog,
|
||||
currency: currency
|
||||
},
|
||||
callback: function(r) {
|
||||
if (!r.exc && r.message) {
|
||||
frappe.model.set_value(cdt, cdn, 'billing_amount', r.message);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var select_loyalty_program = function(frm, loyalty_programs) {
|
||||
var dialog = new frappe.ui.Dialog({
|
||||
title: __("Select Loyalty Program"),
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -290,6 +290,8 @@ class SalesInvoice(SellingController):
|
||||
self.update_time_sheet(None)
|
||||
|
||||
def on_cancel(self):
|
||||
check_if_return_invoice_linked_with_payment_entry(self)
|
||||
|
||||
super(SalesInvoice, self).on_cancel()
|
||||
|
||||
self.check_sales_order_on_hold_or_close("sales_order")
|
||||
@ -480,7 +482,7 @@ class SalesInvoice(SellingController):
|
||||
if not self.pos_profile:
|
||||
pos_profile = get_pos_profile(self.company) or {}
|
||||
if not pos_profile:
|
||||
frappe.throw(_("No POS Profile found. Please create a New POS Profile first"))
|
||||
return
|
||||
self.pos_profile = pos_profile.get('name')
|
||||
|
||||
pos = {}
|
||||
@ -846,6 +848,7 @@ class SalesInvoice(SellingController):
|
||||
self.allocate_advance_taxes(gl_entries)
|
||||
|
||||
self.make_item_gl_entries(gl_entries)
|
||||
self.make_discount_gl_entries(gl_entries)
|
||||
|
||||
# merge gl entries before adding pos entries
|
||||
gl_entries = merge_similar_entries(gl_entries)
|
||||
@ -885,18 +888,22 @@ class SalesInvoice(SellingController):
|
||||
)
|
||||
|
||||
def make_tax_gl_entries(self, gl_entries):
|
||||
enable_discount_accounting = cint(frappe.db.get_single_value('Accounts Settings', 'enable_discount_accounting'))
|
||||
|
||||
for tax in self.get("taxes"):
|
||||
amount, base_amount = self.get_tax_amounts(tax, enable_discount_accounting)
|
||||
|
||||
if flt(tax.base_tax_amount_after_discount_amount):
|
||||
account_currency = get_account_currency(tax.account_head)
|
||||
gl_entries.append(
|
||||
self.get_gl_dict({
|
||||
"account": tax.account_head,
|
||||
"against": self.customer,
|
||||
"credit": flt(tax.base_tax_amount_after_discount_amount,
|
||||
"credit": flt(base_amount,
|
||||
tax.precision("tax_amount_after_discount_amount")),
|
||||
"credit_in_account_currency": (flt(tax.base_tax_amount_after_discount_amount,
|
||||
"credit_in_account_currency": (flt(base_amount,
|
||||
tax.precision("base_tax_amount_after_discount_amount")) if account_currency==self.company_currency else
|
||||
flt(tax.tax_amount_after_discount_amount, tax.precision("tax_amount_after_discount_amount"))),
|
||||
flt(amount, tax.precision("tax_amount_after_discount_amount"))),
|
||||
"cost_center": tax.cost_center
|
||||
}, account_currency, item=tax)
|
||||
)
|
||||
@ -915,6 +922,8 @@ class SalesInvoice(SellingController):
|
||||
|
||||
def make_item_gl_entries(self, gl_entries):
|
||||
# income account gl entries
|
||||
enable_discount_accounting = cint(frappe.db.get_single_value('Accounts Settings', 'enable_discount_accounting'))
|
||||
|
||||
for item in self.get("items"):
|
||||
if flt(item.base_net_amount, item.precision("base_net_amount")):
|
||||
if item.is_fixed_asset:
|
||||
@ -940,15 +949,17 @@ class SalesInvoice(SellingController):
|
||||
income_account = (item.income_account
|
||||
if (not item.enable_deferred_revenue or self.is_return) else item.deferred_revenue_account)
|
||||
|
||||
amount, base_amount = self.get_amount_and_base_amount(item, enable_discount_accounting)
|
||||
|
||||
account_currency = get_account_currency(income_account)
|
||||
gl_entries.append(
|
||||
self.get_gl_dict({
|
||||
"account": income_account,
|
||||
"against": self.customer,
|
||||
"credit": flt(item.base_net_amount, item.precision("base_net_amount")),
|
||||
"credit_in_account_currency": (flt(item.base_net_amount, item.precision("base_net_amount"))
|
||||
"credit": flt(base_amount, item.precision("base_net_amount")),
|
||||
"credit_in_account_currency": (flt(base_amount, item.precision("base_net_amount"))
|
||||
if account_currency==self.company_currency
|
||||
else flt(item.net_amount, item.precision("net_amount"))),
|
||||
else flt(amount, item.precision("net_amount"))),
|
||||
"cost_center": item.cost_center,
|
||||
"project": item.project or self.project
|
||||
}, account_currency, item=item)
|
||||
@ -959,6 +970,12 @@ class SalesInvoice(SellingController):
|
||||
erpnext.is_perpetual_inventory_enabled(self.company):
|
||||
gl_entries += super(SalesInvoice, self).get_gl_entries()
|
||||
|
||||
def set_asset_status(self, asset):
|
||||
if self.is_return:
|
||||
asset.set_status()
|
||||
else:
|
||||
asset.set_status("Sold" if self.docstatus==1 else None)
|
||||
|
||||
def make_loyalty_point_redemption_gle(self, gl_entries):
|
||||
if cint(self.redeem_loyalty_points):
|
||||
gl_entries.append(
|
||||
@ -1924,3 +1941,41 @@ def create_dunning(source_name, target_doc=None):
|
||||
}
|
||||
}, target_doc, set_missing_values)
|
||||
return doclist
|
||||
|
||||
def check_if_return_invoice_linked_with_payment_entry(self):
|
||||
# If a Return invoice is linked with payment entry along with other invoices,
|
||||
# the cancellation of the Return causes allocated amount to be greater than paid
|
||||
|
||||
if not frappe.db.get_single_value('Accounts Settings', 'unlink_payment_on_cancellation_of_invoice'):
|
||||
return
|
||||
|
||||
payment_entries = []
|
||||
if self.is_return and self.return_against:
|
||||
invoice = self.return_against
|
||||
else:
|
||||
invoice = self.name
|
||||
|
||||
payment_entries = frappe.db.sql_list("""
|
||||
SELECT
|
||||
t1.name
|
||||
FROM
|
||||
`tabPayment Entry` t1, `tabPayment Entry Reference` t2
|
||||
WHERE
|
||||
t1.name = t2.parent
|
||||
and t1.docstatus = 1
|
||||
and t2.reference_name = %s
|
||||
and t2.allocated_amount < 0
|
||||
""", invoice)
|
||||
|
||||
links_to_pe = []
|
||||
if payment_entries:
|
||||
for payment in payment_entries:
|
||||
payment_entry = frappe.get_doc("Payment Entry", payment)
|
||||
if len(payment_entry.references) > 1:
|
||||
links_to_pe.append(payment_entry.name)
|
||||
if links_to_pe:
|
||||
payment_entries_link = [get_link_to_form('Payment Entry', name, label=name) for name in links_to_pe]
|
||||
message = _("Please cancel and amend the Payment Entry")
|
||||
message += " " + ", ".join(payment_entries_link) + " "
|
||||
message += _("to unallocate the amount of this Return Invoice before cancelling it.")
|
||||
frappe.throw(message)
|
||||
|
@ -1986,6 +1986,54 @@ class TestSalesInvoice(unittest.TestCase):
|
||||
sales_invoice.save()
|
||||
self.assertEqual(sales_invoice.items[0].item_tax_template, "_Test Account Excise Duty @ 10 - _TC")
|
||||
|
||||
def test_sales_invoice_with_discount_accounting_enabled(self):
|
||||
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import enable_discount_accounting
|
||||
|
||||
enable_discount_accounting()
|
||||
|
||||
discount_account = create_account(account_name="Discount Account",
|
||||
parent_account="Indirect Expenses - _TC", company="_Test Company")
|
||||
si = create_sales_invoice(discount_account=discount_account, discount_percentage=10, rate=90)
|
||||
|
||||
expected_gle = [
|
||||
["Debtors - _TC", 90.0, 0.0, nowdate()],
|
||||
["Discount Account - _TC", 10.0, 0.0, nowdate()],
|
||||
["Sales - _TC", 0.0, 100.0, nowdate()]
|
||||
]
|
||||
|
||||
check_gl_entries(self, si.name, expected_gle, add_days(nowdate(), -1))
|
||||
enable_discount_accounting(enable=0)
|
||||
|
||||
def test_additional_discount_for_sales_invoice_with_discount_accounting_enabled(self):
|
||||
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import enable_discount_accounting
|
||||
|
||||
enable_discount_accounting()
|
||||
additional_discount_account = create_account(account_name="Discount Account",
|
||||
parent_account="Indirect Expenses - _TC", company="_Test Company")
|
||||
|
||||
si = create_sales_invoice(parent_cost_center='Main - _TC', do_not_save=1)
|
||||
si.apply_discount_on = "Grand Total"
|
||||
si.additional_discount_account = additional_discount_account
|
||||
si.additional_discount_percentage = 20
|
||||
si.append("taxes", {
|
||||
"charge_type": "On Net Total",
|
||||
"account_head": "_Test Account VAT - _TC",
|
||||
"cost_center": "Main - _TC",
|
||||
"description": "Test",
|
||||
"rate": 10
|
||||
})
|
||||
si.submit()
|
||||
|
||||
expected_gle = [
|
||||
["_Test Account VAT - _TC", 0.0, 10.0, nowdate()],
|
||||
["Debtors - _TC", 88, 0.0, nowdate()],
|
||||
["Discount Account - _TC", 22.0, 0.0, nowdate()],
|
||||
["Sales - _TC", 0.0, 100.0, nowdate()]
|
||||
]
|
||||
|
||||
check_gl_entries(self, si.name, expected_gle, add_days(nowdate(), -1))
|
||||
enable_discount_accounting(enable=0)
|
||||
|
||||
def get_sales_invoice_for_e_invoice():
|
||||
si = make_sales_invoice_for_ewaybill()
|
||||
si.naming_series = 'INV-2020-.#####'
|
||||
@ -2179,6 +2227,7 @@ def create_sales_invoice(**args):
|
||||
si.currency=args.currency or "INR"
|
||||
si.conversion_rate = args.conversion_rate or 1
|
||||
si.naming_series = args.naming_series or "T-SINV-"
|
||||
si.cost_center = args.parent_cost_center
|
||||
|
||||
si.append("items", {
|
||||
"item_code": args.item or args.item_code or "_Test Item",
|
||||
@ -2190,8 +2239,11 @@ def create_sales_invoice(**args):
|
||||
"uom": args.uom or "Nos",
|
||||
"stock_uom": args.uom or "Nos",
|
||||
"rate": args.rate if args.get("rate") is not None else 100,
|
||||
"price_list_rate": args.price_list_rate if args.get("price_list_rate") is not None else 100,
|
||||
"income_account": args.income_account or "Sales - _TC",
|
||||
"expense_account": args.expense_account or "Cost of Goods Sold - _TC",
|
||||
"discount_account": args.discount_account or None,
|
||||
"discount_amount": args.discount_amount or 0,
|
||||
"cost_center": args.cost_center or "_Test Cost Center - _TC",
|
||||
"serial_no": args.serial_no,
|
||||
"conversion_factor": 1
|
||||
|
@ -63,6 +63,7 @@
|
||||
"finance_book",
|
||||
"col_break4",
|
||||
"expense_account",
|
||||
"discount_account",
|
||||
"deferred_revenue",
|
||||
"deferred_revenue_account",
|
||||
"service_stop_date",
|
||||
@ -821,12 +822,18 @@
|
||||
"no_copy": 1,
|
||||
"options": "currency",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "discount_account",
|
||||
"fieldtype": "Link",
|
||||
"label": "Discount Account",
|
||||
"options": "Account"
|
||||
}
|
||||
],
|
||||
"idx": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-02-23 01:05:22.123527",
|
||||
"modified": "2021-07-05 15:07:22.857128",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Sales Invoice Item",
|
||||
|
@ -9,7 +9,9 @@
|
||||
"description",
|
||||
"billing_hours",
|
||||
"billing_amount",
|
||||
"column_break_5",
|
||||
"time_sheet",
|
||||
"project_name",
|
||||
"timesheet_detail"
|
||||
],
|
||||
"fields": [
|
||||
@ -61,11 +63,21 @@
|
||||
"in_list_view": 1,
|
||||
"label": "Description",
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"fieldname": "column_break_5",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"fieldname": "project_name",
|
||||
"fieldtype": "Data",
|
||||
"label": "Project Name",
|
||||
"read_only": 1
|
||||
}
|
||||
],
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-05-20 22:33:57.234846",
|
||||
"modified": "2021-06-08 14:43:02.748981",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Sales Invoice Timesheet",
|
||||
|
@ -0,0 +1,31 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-05-06 16:17:44.329943",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"sales_partner"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "sales_partner",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Sales Partner ",
|
||||
"options": "Sales Partner"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-05-07 10:43:37.532095",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Sales Partner Item",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class SalesPartnerItem(Document):
|
||||
pass
|
@ -6,7 +6,7 @@ import frappe
|
||||
from frappe import _
|
||||
from frappe.utils import flt
|
||||
from frappe.model.document import Document
|
||||
from erpnext.controllers.accounts_controller import validate_taxes_and_charges, validate_inclusive_tax
|
||||
from erpnext.controllers.accounts_controller import validate_taxes_and_charges, validate_inclusive_tax, validate_cost_center, validate_account_head
|
||||
|
||||
class SalesTaxesandChargesTemplate(Document):
|
||||
def validate(self):
|
||||
@ -39,6 +39,8 @@ def valdiate_taxes_and_charges_template(doc):
|
||||
|
||||
for tax in doc.get("taxes"):
|
||||
validate_taxes_and_charges(tax)
|
||||
validate_account_head(tax, doc)
|
||||
validate_cost_center(tax, doc)
|
||||
validate_inclusive_tax(tax, doc)
|
||||
|
||||
def validate_disabled(doc):
|
||||
|
@ -8,6 +8,7 @@
|
||||
"charge_type": "On Net Total",
|
||||
"description": "VAT",
|
||||
"doctype": "Sales Taxes and Charges",
|
||||
"cost_center": "Main - _TC",
|
||||
"parentfield": "taxes",
|
||||
"rate": 6
|
||||
},
|
||||
@ -16,6 +17,7 @@
|
||||
"charge_type": "On Net Total",
|
||||
"description": "Service Tax",
|
||||
"doctype": "Sales Taxes and Charges",
|
||||
"cost_center": "Main - _TC",
|
||||
"parentfield": "taxes",
|
||||
"rate": 6.36
|
||||
}
|
||||
@ -114,6 +116,7 @@
|
||||
"charge_type": "On Net Total",
|
||||
"description": "VAT",
|
||||
"doctype": "Sales Taxes and Charges",
|
||||
"cost_center": "Main - _TC",
|
||||
"parentfield": "taxes",
|
||||
"rate": 12
|
||||
},
|
||||
@ -122,6 +125,7 @@
|
||||
"charge_type": "On Net Total",
|
||||
"description": "Service Tax",
|
||||
"doctype": "Sales Taxes and Charges",
|
||||
"cost_center": "Main - _TC",
|
||||
"parentfield": "taxes",
|
||||
"rate": 4
|
||||
}
|
||||
@ -137,6 +141,7 @@
|
||||
"charge_type": "On Net Total",
|
||||
"description": "VAT",
|
||||
"doctype": "Sales Taxes and Charges",
|
||||
"cost_center": "Main - _TC",
|
||||
"parentfield": "taxes",
|
||||
"rate": 12
|
||||
},
|
||||
@ -145,6 +150,7 @@
|
||||
"charge_type": "On Net Total",
|
||||
"description": "Service Tax",
|
||||
"doctype": "Sales Taxes and Charges",
|
||||
"cost_center": "Main - _TC",
|
||||
"parentfield": "taxes",
|
||||
"rate": 4
|
||||
}
|
||||
@ -160,6 +166,7 @@
|
||||
"charge_type": "On Net Total",
|
||||
"description": "VAT",
|
||||
"doctype": "Sales Taxes and Charges",
|
||||
"cost_center": "Main - _TC",
|
||||
"parentfield": "taxes",
|
||||
"rate": 12
|
||||
},
|
||||
@ -168,6 +175,7 @@
|
||||
"charge_type": "On Net Total",
|
||||
"description": "Service Tax",
|
||||
"doctype": "Sales Taxes and Charges",
|
||||
"cost_center": "Main - _TC",
|
||||
"parentfield": "taxes",
|
||||
"rate": 4
|
||||
}
|
||||
|
@ -0,0 +1,31 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-05-06 16:19:22.040795",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"supplier_group"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "supplier_group",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Supplier Group",
|
||||
"options": "Supplier Group"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-05-07 10:43:59.877938",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Supplier Group Item",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class SupplierGroupItem(Document):
|
||||
pass
|
0
erpnext/accounts/doctype/supplier_item/__init__.py
Normal file
0
erpnext/accounts/doctype/supplier_item/__init__.py
Normal file
31
erpnext/accounts/doctype/supplier_item/supplier_item.json
Normal file
31
erpnext/accounts/doctype/supplier_item/supplier_item.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-05-06 16:18:54.758468",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"supplier"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "supplier",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Supplier",
|
||||
"options": "Supplier"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-05-07 10:44:09.707778",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Supplier Item",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
8
erpnext/accounts/doctype/supplier_item/supplier_item.py
Normal file
8
erpnext/accounts/doctype/supplier_item/supplier_item.py
Normal file
@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class SupplierItem(Document):
|
||||
pass
|
0
erpnext/accounts/doctype/territory_item/__init__.py
Normal file
0
erpnext/accounts/doctype/territory_item/__init__.py
Normal file
31
erpnext/accounts/doctype/territory_item/territory_item.json
Normal file
31
erpnext/accounts/doctype/territory_item/territory_item.json
Normal file
@ -0,0 +1,31 @@
|
||||
{
|
||||
"actions": [],
|
||||
"creation": "2021-05-06 16:16:51.885441",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"territory"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"fieldname": "territory",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Territory",
|
||||
"options": "Territory"
|
||||
}
|
||||
],
|
||||
"index_web_pages_for_search": 1,
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-05-07 10:43:26.641030",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Accounts",
|
||||
"name": "Territory Item",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
# Copyright (c) 2021, Frappe Technologies Pvt. Ltd. and contributors
|
||||
# For license information, please see license.txt
|
||||
|
||||
# import frappe
|
||||
from frappe.model.document import Document
|
||||
|
||||
class TerritoryItem(Document):
|
||||
pass
|
@ -8,7 +8,7 @@ from frappe import _, msgprint, scrub
|
||||
from frappe.core.doctype.user_permission.user_permission import get_permitted_documents
|
||||
from frappe.model.utils import get_fetch_values
|
||||
from frappe.utils import (add_days, getdate, formatdate, date_diff,
|
||||
add_years, get_timestamp, nowdate, flt, cstr, add_months, get_last_day)
|
||||
add_years, get_timestamp, nowdate, flt, cstr, add_months, get_last_day, cint)
|
||||
from frappe.contacts.doctype.address.address import (get_address_display,
|
||||
get_default_address, get_company_address)
|
||||
from frappe.contacts.doctype.contact.contact import get_contact_details
|
||||
@ -58,7 +58,7 @@ def _get_party_details(party=None, account=None, party_type="Customer", company=
|
||||
customer_group=party_details.customer_group, supplier_group=party_details.supplier_group, tax_category=party_details.tax_category,
|
||||
billing_address=party_address, shipping_address=shipping_address)
|
||||
|
||||
if fetch_payment_terms_template:
|
||||
if cint(fetch_payment_terms_template):
|
||||
party_details["payment_terms_template"] = get_payment_terms_template(party.name, party_type, company)
|
||||
|
||||
if not party_details.get("currency"):
|
||||
|
@ -639,7 +639,7 @@ class TestAsset(unittest.TestCase):
|
||||
asset_name = frappe.db.get_value("Asset", {"purchase_receipt": pr.name}, 'name')
|
||||
asset = frappe.get_doc('Asset', asset_name)
|
||||
asset.calculate_depreciation = 1
|
||||
asset.available_for_use_date = '2030-06-12'
|
||||
asset.available_for_use_date = '2030-07-12'
|
||||
asset.purchase_date = '2030-01-01'
|
||||
asset.append("finance_books", {
|
||||
"expected_value_after_useful_life": 1000,
|
||||
@ -653,10 +653,10 @@ class TestAsset(unittest.TestCase):
|
||||
self.assertEqual(asset.finance_books[0].rate_of_depreciation, 50.0)
|
||||
|
||||
expected_schedules = [
|
||||
["2030-12-31", 1106.85, 1106.85],
|
||||
["2031-12-31", 3446.58, 4553.43],
|
||||
["2032-12-31", 1723.29, 6276.72],
|
||||
["2033-06-12", 723.28, 7000.00]
|
||||
["2030-12-31", 942.47, 942.47],
|
||||
["2031-12-31", 3528.77, 4471.24],
|
||||
["2032-12-31", 1764.38, 6235.62],
|
||||
["2033-07-12", 764.38, 7000.00]
|
||||
]
|
||||
|
||||
schedules = [[cstr(d.schedule_date), flt(d.depreciation_amount, 2), flt(d.accumulated_depreciation_amount, 2)]
|
||||
|
@ -447,10 +447,11 @@ def get_mapped_purchase_invoice(source_name, target_doc=None, ignore_permissions
|
||||
target.flags.ignore_permissions = ignore_permissions
|
||||
set_missing_values(source, target)
|
||||
#Get the advance paid Journal Entries in Purchase Invoice Advance
|
||||
|
||||
if target.get("allocate_advances_automatically"):
|
||||
target.set_advances()
|
||||
|
||||
target.set_payment_schedule()
|
||||
|
||||
def update_item(obj, target, source_parent):
|
||||
target.amount = flt(obj.amount) - flt(obj.billed_amt)
|
||||
target.base_amount = target.amount * flt(source_parent.conversion_rate)
|
||||
@ -470,6 +471,7 @@ def get_mapped_purchase_invoice(source_name, target_doc=None, ignore_permissions
|
||||
"party_account_currency": "party_account_currency",
|
||||
"supplier_warehouse":"supplier_warehouse"
|
||||
},
|
||||
"field_no_map" : ["payment_terms_template"],
|
||||
"validation": {
|
||||
"docstatus": ["=", 1],
|
||||
}
|
||||
@ -489,12 +491,6 @@ def get_mapped_purchase_invoice(source_name, target_doc=None, ignore_permissions
|
||||
},
|
||||
}
|
||||
|
||||
if frappe.get_single("Accounts Settings").automatically_fetch_payment_terms == 1:
|
||||
fields["Payment Schedule"] = {
|
||||
"doctype": "Payment Schedule",
|
||||
"add_if_empty": True
|
||||
}
|
||||
|
||||
doc = get_mapped_doc("Purchase Order", source_name, fields,
|
||||
target_doc, postprocess, ignore_permissions=ignore_permissions)
|
||||
|
||||
|
@ -484,6 +484,9 @@ class TestPurchaseOrder(unittest.TestCase):
|
||||
|
||||
|
||||
def test_make_purchase_invoice_with_terms(self):
|
||||
from erpnext.selling.doctype.sales_order.test_sales_order import automatically_fetch_payment_terms, compare_payment_schedules
|
||||
|
||||
automatically_fetch_payment_terms()
|
||||
po = create_purchase_order(do_not_save=True)
|
||||
|
||||
self.assertRaises(frappe.ValidationError, make_pi_from_po, po.name)
|
||||
@ -509,6 +512,7 @@ class TestPurchaseOrder(unittest.TestCase):
|
||||
self.assertEqual(getdate(pi.payment_schedule[0].due_date), getdate(po.transaction_date))
|
||||
self.assertEqual(pi.payment_schedule[1].payment_amount, 2500.0)
|
||||
self.assertEqual(getdate(pi.payment_schedule[1].due_date), add_days(getdate(po.transaction_date), 30))
|
||||
automatically_fetch_payment_terms(enable=0)
|
||||
|
||||
def test_subcontracting(self):
|
||||
po = create_purchase_order(item_code="_Test FG Item", is_subcontracted="Yes")
|
||||
@ -632,14 +636,18 @@ class TestPurchaseOrder(unittest.TestCase):
|
||||
else:
|
||||
raise Exception
|
||||
|
||||
def test_terms_does_not_copy(self):
|
||||
po = create_purchase_order()
|
||||
|
||||
self.assertTrue(po.get('payment_schedule'))
|
||||
def test_terms_are_not_copied_if_automatically_fetch_payment_terms_is_unchecked(self):
|
||||
po = create_purchase_order(do_not_save=1)
|
||||
po.payment_terms_template = '_Test Payment Term Template'
|
||||
po.save()
|
||||
po.submit()
|
||||
|
||||
frappe.db.set_value('Company', '_Test Company', 'payment_terms', '_Test Payment Term Template 1')
|
||||
pi = make_pi_from_po(po.name)
|
||||
pi.save()
|
||||
|
||||
self.assertFalse(pi.get('payment_schedule'))
|
||||
self.assertEqual(pi.get('payment_terms_template'), '_Test Payment Term Template 1')
|
||||
frappe.db.set_value('Company', '_Test Company', 'payment_terms', '')
|
||||
|
||||
def test_terms_copied(self):
|
||||
po = create_purchase_order(do_not_save=1)
|
||||
@ -968,8 +976,27 @@ class TestPurchaseOrder(unittest.TestCase):
|
||||
# To test if the PO does NOT have a Blanket Order
|
||||
self.assertEqual(po_doc.items[0].blanket_order, None)
|
||||
|
||||
def test_payment_terms_are_fetched_when_creating_purchase_invoice(self):
|
||||
from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_terms_template
|
||||
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
|
||||
from erpnext.selling.doctype.sales_order.test_sales_order import automatically_fetch_payment_terms, compare_payment_schedules
|
||||
|
||||
automatically_fetch_payment_terms()
|
||||
|
||||
po = create_purchase_order(qty=10, rate=100, do_not_save=1)
|
||||
create_payment_terms_template()
|
||||
po.payment_terms_template = 'Test Receivable Template'
|
||||
po.submit()
|
||||
|
||||
pi = make_purchase_invoice(qty=10, rate=100, do_not_save=1)
|
||||
pi.items[0].purchase_order = po.name
|
||||
pi.items[0].po_detail = po.items[0].name
|
||||
pi.insert()
|
||||
|
||||
# self.assertEqual(po.payment_terms_template, pi.payment_terms_template)
|
||||
compare_payment_schedules(self, po, pi)
|
||||
|
||||
automatically_fetch_payment_terms(enable=0)
|
||||
|
||||
def make_pr_against_po(po, received_qty=0):
|
||||
pr = make_purchase_receipt(po)
|
||||
|
@ -813,6 +813,89 @@ class AccountsController(TransactionBase):
|
||||
tax_map[tax.account_head] -= allocated_amount
|
||||
allocated_tax_map[tax.account_head] -= allocated_amount
|
||||
|
||||
def get_amount_and_base_amount(self, item, enable_discount_accounting):
|
||||
amount = item.net_amount
|
||||
base_amount = item.base_net_amount
|
||||
|
||||
if enable_discount_accounting and self.get('discount_amount') and self.get('additional_discount_account'):
|
||||
amount = item.amount
|
||||
base_amount = item.base_amount
|
||||
|
||||
return amount, base_amount
|
||||
|
||||
def get_tax_amounts(self, tax, enable_discount_accounting):
|
||||
amount = tax.tax_amount_after_discount_amount
|
||||
base_amount = tax.base_tax_amount_after_discount_amount
|
||||
|
||||
if enable_discount_accounting and self.get('discount_amount') and self.get('additional_discount_account') \
|
||||
and self.get('apply_discount_on') == 'Grand Total':
|
||||
amount = tax.tax_amount
|
||||
base_amount = tax.base_tax_amount
|
||||
|
||||
return amount, base_amount
|
||||
|
||||
def make_discount_gl_entries(self, gl_entries):
|
||||
enable_discount_accounting = cint(frappe.db.get_single_value('Accounts Settings', 'enable_discount_accounting'))
|
||||
|
||||
if enable_discount_accounting:
|
||||
if self.doctype == "Purchase Invoice":
|
||||
dr_or_cr = "credit"
|
||||
rev_dr_cr = "debit"
|
||||
supplier_or_customer = self.supplier
|
||||
|
||||
else:
|
||||
dr_or_cr = "debit"
|
||||
rev_dr_cr = "credit"
|
||||
supplier_or_customer = self.customer
|
||||
|
||||
for item in self.get("items"):
|
||||
if item.get('discount_amount') and item.get('discount_account'):
|
||||
discount_amount = item.discount_amount * item.qty
|
||||
if self.doctype == "Purchase Invoice":
|
||||
income_or_expense_account = (item.expense_account
|
||||
if (not item.enable_deferred_expense or self.is_return)
|
||||
else item.deferred_expense_account)
|
||||
else:
|
||||
income_or_expense_account = (item.income_account
|
||||
if (not item.enable_deferred_revenue or self.is_return)
|
||||
else item.deferred_revenue_account)
|
||||
|
||||
account_currency = get_account_currency(item.discount_account)
|
||||
gl_entries.append(
|
||||
self.get_gl_dict({
|
||||
"account": item.discount_account,
|
||||
"against": supplier_or_customer,
|
||||
dr_or_cr: flt(discount_amount, item.precision('discount_amount')),
|
||||
dr_or_cr + "_in_account_currency": flt(discount_amount * self.get('conversion_rate'),
|
||||
item.precision('discount_amount')),
|
||||
"cost_center": item.cost_center,
|
||||
"project": item.project
|
||||
}, account_currency, item=item)
|
||||
)
|
||||
|
||||
account_currency = get_account_currency(income_or_expense_account)
|
||||
gl_entries.append(
|
||||
self.get_gl_dict({
|
||||
"account": income_or_expense_account,
|
||||
"against": supplier_or_customer,
|
||||
rev_dr_cr: flt(discount_amount, item.precision('discount_amount')),
|
||||
rev_dr_cr + "_in_account_currency": flt(discount_amount * self.get('conversion_rate'),
|
||||
item.precision('discount_amount')),
|
||||
"cost_center": item.cost_center,
|
||||
"project": item.project or self.project
|
||||
}, account_currency, item=item)
|
||||
)
|
||||
|
||||
if self.get('discount_amount') and self.get('additional_discount_account'):
|
||||
gl_entries.append(
|
||||
self.get_gl_dict({
|
||||
"account": self.additional_discount_account,
|
||||
"against": supplier_or_customer,
|
||||
dr_or_cr: self.discount_amount,
|
||||
"cost_center": self.cost_center
|
||||
}, item=self)
|
||||
)
|
||||
|
||||
def allocate_advance_taxes(self, gl_entries):
|
||||
tax_map = self.get_tax_map()
|
||||
for pe in self.get("advances"):
|
||||
@ -1096,6 +1179,8 @@ class AccountsController(TransactionBase):
|
||||
if self.doctype in ("Sales Invoice", "Purchase Invoice"):
|
||||
base_grand_total = base_grand_total - flt(self.base_write_off_amount)
|
||||
grand_total = grand_total - flt(self.write_off_amount)
|
||||
po_or_so, doctype, fieldname = self.get_order_details()
|
||||
automatically_fetch_payment_terms = cint(frappe.db.get_single_value('Accounts Settings', 'automatically_fetch_payment_terms'))
|
||||
|
||||
if self.get("total_advance"):
|
||||
if party_account_currency == self.company_currency:
|
||||
@ -1106,22 +1191,86 @@ class AccountsController(TransactionBase):
|
||||
base_grand_total = flt(grand_total * self.get("conversion_rate"), self.precision("base_grand_total"))
|
||||
|
||||
if not self.get("payment_schedule"):
|
||||
if self.get("payment_terms_template"):
|
||||
if self.doctype in ["Sales Invoice", "Purchase Invoice"] and automatically_fetch_payment_terms \
|
||||
and self.linked_order_has_payment_terms(po_or_so, fieldname, doctype):
|
||||
self.fetch_payment_terms_from_order(po_or_so, doctype)
|
||||
if self.get('payment_terms_template'):
|
||||
self.ignore_default_payment_terms_template = 1
|
||||
elif self.get("payment_terms_template"):
|
||||
data = get_payment_terms(self.payment_terms_template, posting_date, grand_total, base_grand_total)
|
||||
for item in data:
|
||||
self.append("payment_schedule", item)
|
||||
else:
|
||||
elif self.doctype not in ["Purchase Receipt"]:
|
||||
data = dict(due_date=due_date, invoice_portion=100, payment_amount=grand_total, base_payment_amount=base_grand_total)
|
||||
self.append("payment_schedule", data)
|
||||
else:
|
||||
for d in self.get("payment_schedule"):
|
||||
if d.invoice_portion:
|
||||
d.payment_amount = flt(grand_total * flt(d.invoice_portion / 100), d.precision('payment_amount'))
|
||||
d.base_payment_amount = flt(base_grand_total * flt(d.invoice_portion / 100), d.precision('base_payment_amount'))
|
||||
d.outstanding = d.payment_amount
|
||||
elif not d.invoice_portion:
|
||||
d.base_payment_amount = flt(base_grand_total * self.get("conversion_rate"), d.precision('base_payment_amount'))
|
||||
|
||||
for d in self.get("payment_schedule"):
|
||||
if d.invoice_portion:
|
||||
d.payment_amount = flt(grand_total * flt(d.invoice_portion / 100), d.precision('payment_amount'))
|
||||
d.base_payment_amount = flt(base_grand_total * flt(d.invoice_portion / 100), d.precision('base_payment_amount'))
|
||||
d.outstanding = d.payment_amount
|
||||
elif not d.invoice_portion:
|
||||
d.base_payment_amount = flt(base_grand_total * self.get("conversion_rate"), d.precision('base_payment_amount'))
|
||||
|
||||
|
||||
def get_order_details(self):
|
||||
if self.doctype == "Sales Invoice":
|
||||
po_or_so = self.get('items')[0].get('sales_order')
|
||||
po_or_so_doctype = "Sales Order"
|
||||
po_or_so_doctype_name = "sales_order"
|
||||
|
||||
else:
|
||||
po_or_so = self.get('items')[0].get('purchase_order')
|
||||
po_or_so_doctype = "Purchase Order"
|
||||
po_or_so_doctype_name = "purchase_order"
|
||||
|
||||
return po_or_so, po_or_so_doctype, po_or_so_doctype_name
|
||||
|
||||
def linked_order_has_payment_terms(self, po_or_so, fieldname, doctype):
|
||||
if po_or_so and self.all_items_have_same_po_or_so(po_or_so, fieldname):
|
||||
if self.linked_order_has_payment_terms_template(po_or_so, doctype):
|
||||
return True
|
||||
elif self.linked_order_has_payment_schedule(po_or_so):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def all_items_have_same_po_or_so(self, po_or_so, fieldname):
|
||||
for item in self.get('items'):
|
||||
if item.get(fieldname) != po_or_so:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def linked_order_has_payment_terms_template(self, po_or_so, doctype):
|
||||
return frappe.get_value(doctype, po_or_so, 'payment_terms_template')
|
||||
|
||||
def linked_order_has_payment_schedule(self, po_or_so):
|
||||
return frappe.get_all('Payment Schedule', filters={'parent': po_or_so})
|
||||
|
||||
def fetch_payment_terms_from_order(self, po_or_so, po_or_so_doctype):
|
||||
"""
|
||||
Fetch Payment Terms from Purchase/Sales Order on creating a new Purchase/Sales Invoice.
|
||||
"""
|
||||
po_or_so = frappe.get_cached_doc(po_or_so_doctype, po_or_so)
|
||||
|
||||
self.payment_schedule = []
|
||||
self.payment_terms_template = po_or_so.payment_terms_template
|
||||
|
||||
for schedule in po_or_so.payment_schedule:
|
||||
payment_schedule = {
|
||||
'payment_term': schedule.payment_term,
|
||||
'due_date': schedule.due_date,
|
||||
'invoice_portion': schedule.invoice_portion,
|
||||
'mode_of_payment': schedule.mode_of_payment,
|
||||
'description': schedule.description
|
||||
}
|
||||
|
||||
if schedule.discount_type == 'Percentage':
|
||||
payment_schedule['discount_type'] = schedule.discount_type
|
||||
payment_schedule['discount'] = schedule.discount
|
||||
|
||||
self.append("payment_schedule", payment_schedule)
|
||||
|
||||
def set_due_date(self):
|
||||
due_dates = [d.due_date for d in self.get("payment_schedule") if d.due_date]
|
||||
@ -1288,6 +1437,27 @@ def validate_taxes_and_charges(tax):
|
||||
tax.rate = None
|
||||
|
||||
|
||||
def validate_account_head(tax, doc):
|
||||
company = frappe.get_cached_value('Account',
|
||||
tax.account_head, 'company')
|
||||
|
||||
if company != doc.company:
|
||||
frappe.throw(_('Row {0}: Account {1} does not belong to Company {2}')
|
||||
.format(tax.idx, frappe.bold(tax.account_head), frappe.bold(doc.company)), title=_('Invalid Account'))
|
||||
|
||||
|
||||
def validate_cost_center(tax, doc):
|
||||
if not tax.cost_center:
|
||||
return
|
||||
|
||||
company = frappe.get_cached_value('Cost Center',
|
||||
tax.cost_center, 'company')
|
||||
|
||||
if company != doc.company:
|
||||
frappe.throw(_('Row {0}: Cost Center {1} does not belong to Company {2}')
|
||||
.format(tax.idx, frappe.bold(tax.cost_center), frappe.bold(doc.company)), title=_('Invalid Cost Center'))
|
||||
|
||||
|
||||
def validate_inclusive_tax(tax, doc):
|
||||
def _on_previous_row_error(row_range):
|
||||
throw(_("To include tax in row {0} in Item rate, taxes in rows {1} must also be included").format(tax.idx, row_range))
|
||||
@ -1808,4 +1978,4 @@ def validate_regional(doc):
|
||||
|
||||
@erpnext.allow_regional
|
||||
def validate_einvoice_fields(doc):
|
||||
pass
|
||||
pass
|
@ -72,7 +72,8 @@ class BuyingController(StockController, Subcontracting):
|
||||
# set contact and address details for supplier, if they are not mentioned
|
||||
if getattr(self, "supplier", None):
|
||||
self.update_if_missing(get_party_details(self.supplier, party_type="Supplier", ignore_permissions=self.flags.ignore_permissions,
|
||||
doctype=self.doctype, company=self.company, party_address=self.supplier_address, shipping_address=self.get('shipping_address')))
|
||||
doctype=self.doctype, company=self.company, party_address=self.supplier_address, shipping_address=self.get('shipping_address'),
|
||||
fetch_payment_terms_template= not self.get('ignore_default_payment_terms_template')))
|
||||
|
||||
self.set_missing_item_details(for_validate)
|
||||
|
||||
|
@ -27,6 +27,7 @@ class StockController(AccountsController):
|
||||
if not self.get('is_return'):
|
||||
self.validate_inspection()
|
||||
self.validate_serialized_batch()
|
||||
self.clean_serial_nos()
|
||||
self.validate_customer_provided_item()
|
||||
self.set_rate_of_stock_uom()
|
||||
self.validate_internal_transfer()
|
||||
@ -72,6 +73,12 @@ class StockController(AccountsController):
|
||||
frappe.throw(_("Row #{0}: The batch {1} has already expired.")
|
||||
.format(d.idx, get_link_to_form("Batch", d.get("batch_no"))))
|
||||
|
||||
def clean_serial_nos(self):
|
||||
for row in self.get("items"):
|
||||
if hasattr(row, "serial_no") and row.serial_no:
|
||||
# replace commas by linefeed and remove all spaces in string
|
||||
row.serial_no = row.serial_no.replace(",", "\n").replace(" ", "")
|
||||
|
||||
def get_gl_entries(self, warehouse_account=None, default_expense_account=None,
|
||||
default_cost_center=None):
|
||||
|
||||
|
0
erpnext/hr/page/organizational_chart/__init__.py
Normal file
0
erpnext/hr/page/organizational_chart/__init__.py
Normal file
21
erpnext/hr/page/organizational_chart/organizational_chart.js
Normal file
21
erpnext/hr/page/organizational_chart/organizational_chart.js
Normal file
@ -0,0 +1,21 @@
|
||||
frappe.pages['organizational-chart'].on_page_load = function(wrapper) {
|
||||
frappe.ui.make_app_page({
|
||||
parent: wrapper,
|
||||
title: __('Organizational Chart'),
|
||||
single_column: true
|
||||
});
|
||||
|
||||
$(wrapper).bind('show', () => {
|
||||
frappe.require('/assets/js/hierarchy-chart.min.js', () => {
|
||||
let organizational_chart = undefined;
|
||||
let method = 'erpnext.hr.page.organizational_chart.organizational_chart.get_children';
|
||||
|
||||
if (frappe.is_mobile()) {
|
||||
organizational_chart = new erpnext.HierarchyChartMobile('Employee', wrapper, method);
|
||||
} else {
|
||||
organizational_chart = new erpnext.HierarchyChart('Employee', wrapper, method);
|
||||
}
|
||||
organizational_chart.show();
|
||||
});
|
||||
});
|
||||
};
|
@ -0,0 +1,26 @@
|
||||
{
|
||||
"content": null,
|
||||
"creation": "2021-05-25 10:53:10.107241",
|
||||
"docstatus": 0,
|
||||
"doctype": "Page",
|
||||
"idx": 0,
|
||||
"modified": "2021-05-25 10:53:18.201931",
|
||||
"modified_by": "Administrator",
|
||||
"module": "HR",
|
||||
"name": "organizational-chart",
|
||||
"owner": "Administrator",
|
||||
"page_name": "Organizational Chart",
|
||||
"roles": [
|
||||
{
|
||||
"role": "HR User"
|
||||
},
|
||||
{
|
||||
"role": "HR Manager"
|
||||
}
|
||||
],
|
||||
"script": null,
|
||||
"standard": "Yes",
|
||||
"style": null,
|
||||
"system_page": 0,
|
||||
"title": "Organizational Chart"
|
||||
}
|
47
erpnext/hr/page/organizational_chart/organizational_chart.py
Normal file
47
erpnext/hr/page/organizational_chart/organizational_chart.py
Normal file
@ -0,0 +1,47 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_children(parent=None, company=None, exclude_node=None):
|
||||
filters = [['status', '!=', 'Left']]
|
||||
if company and company != 'All Companies':
|
||||
filters.append(['company', '=', company])
|
||||
|
||||
if parent and company and parent != company:
|
||||
filters.append(['reports_to', '=', parent])
|
||||
else:
|
||||
filters.append(['reports_to', '=', ''])
|
||||
|
||||
if exclude_node:
|
||||
filters.append(['name', '!=', exclude_node])
|
||||
|
||||
employees = frappe.get_list('Employee',
|
||||
fields=['employee_name as name', 'name as id', 'reports_to', 'image', 'designation as title'],
|
||||
filters=filters,
|
||||
order_by='name'
|
||||
)
|
||||
|
||||
for employee in employees:
|
||||
is_expandable = frappe.db.count('Employee', filters={'reports_to': employee.get('id')})
|
||||
employee.connections = get_connections(employee.id)
|
||||
employee.expandable = 1 if is_expandable else 0
|
||||
|
||||
return employees
|
||||
|
||||
|
||||
def get_connections(employee):
|
||||
num_connections = 0
|
||||
|
||||
connections = frappe.get_list('Employee', filters=[
|
||||
['reports_to', '=', employee]
|
||||
])
|
||||
num_connections += len(connections)
|
||||
|
||||
while connections:
|
||||
for entry in connections:
|
||||
connections = frappe.get_list('Employee', filters=[
|
||||
['reports_to', '=', entry.name]
|
||||
])
|
||||
num_connections += len(connections)
|
||||
|
||||
return num_connections
|
@ -294,6 +294,7 @@ erpnext.patches.v13_0.update_level_in_bom #1234sswef
|
||||
erpnext.patches.v13_0.add_missing_fg_item_for_stock_entry
|
||||
erpnext.patches.v13_0.update_subscription_status_in_memberships
|
||||
erpnext.patches.v13_0.update_amt_in_work_order_required_items
|
||||
erpnext.patches.v12_0.show_einvoice_irn_cancelled_field
|
||||
erpnext.patches.v13_0.delete_orphaned_tables
|
||||
erpnext.patches.v13_0.update_export_type_for_gst
|
||||
erpnext.patches.v13_0.update_tds_check_field #3
|
||||
|
12
erpnext/patches/v12_0/show_einvoice_irn_cancelled_field.py
Normal file
12
erpnext/patches/v12_0/show_einvoice_irn_cancelled_field.py
Normal file
@ -0,0 +1,12 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
|
||||
def execute():
|
||||
company = frappe.get_all('Company', filters = {'country': 'India'})
|
||||
if not company:
|
||||
return
|
||||
|
||||
irn_cancelled_field = frappe.db.exists('Custom Field', {'dt': 'Sales Invoice', 'fieldname': 'irn_cancelled'})
|
||||
if irn_cancelled_field:
|
||||
frappe.db.set_value('Custom Field', irn_cancelled_field, 'depends_on', 'eval: doc.irn')
|
||||
frappe.db.set_value('Custom Field', irn_cancelled_field, 'read_only', 0)
|
@ -310,6 +310,7 @@
|
||||
"read_only": 1
|
||||
},
|
||||
{
|
||||
"default": "1",
|
||||
"fieldname": "exchange_rate",
|
||||
"fieldtype": "Float",
|
||||
"label": "Exchange Rate"
|
||||
@ -319,7 +320,7 @@
|
||||
"idx": 1,
|
||||
"is_submittable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-05-18 16:10:08.249619",
|
||||
"modified": "2021-06-09 12:08:53.930200",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Projects",
|
||||
"name": "Timesheet",
|
||||
|
@ -227,7 +227,8 @@ def get_projectwise_timesheet_data(project=None, parent=None, from_time=None, to
|
||||
return frappe.db.sql("""SELECT tsd.name as name,
|
||||
tsd.parent as parent, tsd.billing_hours as billing_hours,
|
||||
tsd.billing_amount as billing_amount, tsd.activity_type as activity_type,
|
||||
tsd.description as description, ts.currency as currency
|
||||
tsd.description as description, ts.currency as currency,
|
||||
tsd.project_name as project_name
|
||||
FROM `tabTimesheet Detail` tsd
|
||||
INNER JOIN `tabTimesheet` ts ON ts.name = tsd.parent
|
||||
WHERE tsd.parenttype = 'Timesheet'
|
||||
@ -235,6 +236,19 @@ def get_projectwise_timesheet_data(project=None, parent=None, from_time=None, to
|
||||
and tsd.is_billable = 1
|
||||
and tsd.sales_invoice is null""".format(condition), {'project': project, 'parent': parent, 'from_time': from_time, 'to_time': to_time}, as_dict=1)
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_timesheet_detail_rate(timelog, currency):
|
||||
timelog_detail = frappe.db.sql("""SELECT tsd.billing_amount as billing_amount,
|
||||
ts.currency as currency FROM `tabTimesheet Detail` tsd
|
||||
INNER JOIN `tabTimesheet` ts ON ts.name=tsd.parent
|
||||
WHERE tsd.name = '{0}'""".format(timelog), as_dict = 1)[0]
|
||||
|
||||
if timelog_detail.currency:
|
||||
exchange_rate = get_exchange_rate(timelog_detail.currency, currency)
|
||||
|
||||
return timelog_detail.billing_amount * exchange_rate
|
||||
return timelog_detail.billing_amount
|
||||
|
||||
@frappe.whitelist()
|
||||
@frappe.validate_and_sanitize_search_inputs
|
||||
def get_timesheet(doctype, txt, searchfield, start, page_len, filters):
|
||||
|
@ -3,7 +3,8 @@
|
||||
"public/less/erpnext.less",
|
||||
"public/less/hub.less",
|
||||
"public/scss/call_popup.scss",
|
||||
"public/scss/point-of-sale.scss"
|
||||
"public/scss/point-of-sale.scss",
|
||||
"public/scss/hierarchy_chart.scss"
|
||||
],
|
||||
"css/marketplace.css": [
|
||||
"public/less/hub.less"
|
||||
@ -43,7 +44,8 @@
|
||||
"public/js/call_popup/call_popup.js",
|
||||
"public/js/utils/dimension_tree_filter.js",
|
||||
"public/js/telephony.js",
|
||||
"public/js/templates/call_link.html"
|
||||
"public/js/templates/call_link.html",
|
||||
"public/js/templates/node_card.html"
|
||||
],
|
||||
"js/item-dashboard.min.js": [
|
||||
"stock/dashboard/item_dashboard.html",
|
||||
@ -66,5 +68,9 @@
|
||||
"public/js/bank_reconciliation_tool/data_table_manager.js",
|
||||
"public/js/bank_reconciliation_tool/number_card.js",
|
||||
"public/js/bank_reconciliation_tool/dialog_manager.js"
|
||||
],
|
||||
"js/hierarchy-chart.min.js": [
|
||||
"public/js/hierarchy_chart/hierarchy_chart_desktop.js",
|
||||
"public/js/hierarchy_chart/hierarchy_chart_mobile.js"
|
||||
]
|
||||
}
|
||||
|
@ -31,6 +31,14 @@ frappe.ui.form.on(cur_frm.doctype, {
|
||||
}
|
||||
}
|
||||
});
|
||||
frm.set_query("cost_center", "taxes", function(doc) {
|
||||
return {
|
||||
filters: {
|
||||
"company": doc.company,
|
||||
"is_group": 0
|
||||
}
|
||||
};
|
||||
});
|
||||
}
|
||||
},
|
||||
validate: function(frm) {
|
||||
|
@ -47,7 +47,10 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
||||
|
||||
if (in_list(["Sales Invoice", "POS Invoice"], this.frm.doc.doctype) && this.frm.doc.is_pos &&
|
||||
this.frm.doc.is_return) {
|
||||
this.update_paid_amount_for_return();
|
||||
if (this.frm.doc.doctype == "Sales Invoice") {
|
||||
this.set_total_amount_to_default_mop();
|
||||
}
|
||||
this.calculate_paid_amount();
|
||||
}
|
||||
|
||||
// Sales person's commission
|
||||
@ -730,7 +733,7 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
||||
}
|
||||
},
|
||||
|
||||
update_paid_amount_for_return: function() {
|
||||
set_total_amount_to_default_mop: function() {
|
||||
var grand_total = this.frm.doc.rounded_total || this.frm.doc.grand_total;
|
||||
|
||||
if(this.frm.doc.party_account_currency == this.frm.doc.currency) {
|
||||
@ -743,15 +746,12 @@ erpnext.taxes_and_totals = erpnext.payments.extend({
|
||||
precision("base_grand_total")
|
||||
);
|
||||
}
|
||||
|
||||
this.frm.doc.payments.find(pay => {
|
||||
if (pay.default) {
|
||||
pay.amount = total_amount_to_pay;
|
||||
}
|
||||
});
|
||||
this.frm.refresh_fields();
|
||||
|
||||
this.calculate_paid_amount();
|
||||
},
|
||||
|
||||
set_default_payment: function(total_amount_to_pay, update_paid_amount) {
|
||||
|
@ -732,7 +732,7 @@ erpnext.TransactionController = erpnext.taxes_and_totals.extend({
|
||||
this.frm.trigger("item_code", cdt, cdn);
|
||||
}
|
||||
else {
|
||||
// Replacing all occurences of comma with carriage return
|
||||
// Replace all occurences of comma with line feed
|
||||
item.serial_no = item.serial_no.replace(/,/g, '\n');
|
||||
item.conversion_factor = item.conversion_factor || 1;
|
||||
refresh_field("serial_no", item.name, item.parentfield);
|
||||
|
591
erpnext/public/js/hierarchy_chart/hierarchy_chart_desktop.js
Normal file
591
erpnext/public/js/hierarchy_chart/hierarchy_chart_desktop.js
Normal file
@ -0,0 +1,591 @@
|
||||
import html2canvas from 'html2canvas';
|
||||
erpnext.HierarchyChart = class {
|
||||
/* Options:
|
||||
- doctype
|
||||
- wrapper: wrapper for the hierarchy view
|
||||
- method:
|
||||
- to get the data for each node
|
||||
- this method should return id, name, title, image, and connections for each node
|
||||
*/
|
||||
constructor(doctype, wrapper, method) {
|
||||
this.page = wrapper.page;
|
||||
this.method = method;
|
||||
this.doctype = doctype;
|
||||
|
||||
this.setup_page_style();
|
||||
this.page.main.addClass('frappe-card');
|
||||
|
||||
this.nodes = {};
|
||||
this.setup_node_class();
|
||||
}
|
||||
|
||||
setup_page_style() {
|
||||
this.page.main.css({
|
||||
'min-height': '300px',
|
||||
'max-height': '600px',
|
||||
'overflow': 'auto',
|
||||
'position': 'relative'
|
||||
});
|
||||
}
|
||||
|
||||
setup_node_class() {
|
||||
let me = this;
|
||||
this.Node = class {
|
||||
constructor({
|
||||
id, parent, parent_id, image, name, title, expandable, connections, is_root // eslint-disable-line
|
||||
}) {
|
||||
// to setup values passed via constructor
|
||||
$.extend(this, arguments[0]);
|
||||
|
||||
this.expanded = 0;
|
||||
|
||||
me.nodes[this.id] = this;
|
||||
me.make_node_element(this);
|
||||
|
||||
if (!me.all_nodes_expanded) {
|
||||
me.setup_node_click_action(this);
|
||||
}
|
||||
|
||||
me.setup_edit_node_action(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
make_node_element(node) {
|
||||
let node_card = frappe.render_template('node_card', {
|
||||
id: node.id,
|
||||
name: node.name,
|
||||
title: node.title,
|
||||
image: node.image,
|
||||
parent: node.parent_id,
|
||||
connections: node.connections,
|
||||
is_mobile: false
|
||||
});
|
||||
|
||||
node.parent.append(node_card);
|
||||
node.$link = $(`#${node.id}`);
|
||||
}
|
||||
|
||||
show() {
|
||||
frappe.breadcrumbs.add('HR');
|
||||
|
||||
this.setup_actions();
|
||||
if ($(`[data-fieldname="company"]`).length) return;
|
||||
let me = this;
|
||||
|
||||
let company = this.page.add_field({
|
||||
fieldtype: 'Link',
|
||||
options: 'Company',
|
||||
fieldname: 'company',
|
||||
placeholder: __('Select Company'),
|
||||
default: frappe.defaults.get_default('company'),
|
||||
only_select: true,
|
||||
reqd: 1,
|
||||
change: () => {
|
||||
me.company = undefined;
|
||||
|
||||
if (company.get_value() && me.company != company.get_value()) {
|
||||
me.company = company.get_value();
|
||||
|
||||
// svg for connectors
|
||||
me.make_svg_markers();
|
||||
me.setup_hierarchy();
|
||||
me.render_root_nodes();
|
||||
me.all_nodes_expanded = false;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
company.refresh();
|
||||
$(`[data-fieldname="company"]`).trigger('change');
|
||||
}
|
||||
|
||||
setup_actions() {
|
||||
let me = this;
|
||||
this.page.add_inner_button(__('Export'), function() {
|
||||
me.export_chart();
|
||||
});
|
||||
|
||||
this.page.add_inner_button(__('Expand All'), function() {
|
||||
me.load_children(me.root_node, true);
|
||||
me.all_nodes_expanded = true;
|
||||
|
||||
me.page.remove_inner_button(__('Expand All'));
|
||||
me.page.add_inner_button(__('Collapse All'), function() {
|
||||
me.setup_hierarchy();
|
||||
me.render_root_nodes();
|
||||
me.all_nodes_expanded = false;
|
||||
|
||||
me.page.remove_inner_button(__('Collapse All'));
|
||||
me.setup_actions();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export_chart() {
|
||||
this.page.main.css({
|
||||
'min-height': '',
|
||||
'max-height': '',
|
||||
'overflow': 'visible',
|
||||
'position': 'fixed',
|
||||
'left': '0',
|
||||
'top': '0'
|
||||
});
|
||||
|
||||
$('.node-card').addClass('exported');
|
||||
|
||||
html2canvas(document.querySelector('#hierarchy-chart-wrapper'), {
|
||||
scrollY: -window.scrollY,
|
||||
scrollX: 0
|
||||
}).then(function(canvas) {
|
||||
// Export the canvas to its data URI representation
|
||||
let dataURL = canvas.toDataURL('image/png');
|
||||
|
||||
// download the image
|
||||
let a = document.createElement('a');
|
||||
a.href = dataURL;
|
||||
a.download = 'hierarchy_chart';
|
||||
a.click();
|
||||
});
|
||||
|
||||
this.setup_page_style();
|
||||
$('.node-card').removeClass('exported');
|
||||
}
|
||||
|
||||
setup_hierarchy() {
|
||||
if (this.$hierarchy)
|
||||
this.$hierarchy.remove();
|
||||
|
||||
$(`#connectors`).empty();
|
||||
|
||||
// setup hierarchy
|
||||
this.$hierarchy = $(
|
||||
`<ul class="hierarchy">
|
||||
<li class="root-level level">
|
||||
<ul class="node-children"></ul>
|
||||
</li>
|
||||
</ul>`);
|
||||
|
||||
this.page.main
|
||||
.find('#hierarchy-chart-wrapper')
|
||||
.append(this.$hierarchy);
|
||||
this.nodes = {};
|
||||
}
|
||||
|
||||
make_svg_markers() {
|
||||
$('#hierarchy-chart-wrapper').remove();
|
||||
|
||||
this.page.main.append(`
|
||||
<div id="hierarchy-chart-wrapper">
|
||||
<svg id="arrows" width="100%" height="100%">
|
||||
<defs>
|
||||
<marker id="arrowhead-active" viewBox="0 0 10 10" refX="3" refY="5" markerWidth="6" markerHeight="6" orient="auto" fill="var(--blue-500)">
|
||||
<path d="M 0 0 L 10 5 L 0 10 z"></path>
|
||||
</marker>
|
||||
<marker id="arrowhead-collapsed" viewBox="0 0 10 10" refX="3" refY="5" markerWidth="6" markerHeight="6" orient="auto" fill="var(--blue-300)">
|
||||
<path d="M 0 0 L 10 5 L 0 10 z"></path>
|
||||
</marker>
|
||||
|
||||
<marker id="arrowstart-active" viewBox="0 0 10 10" refX="3" refY="5" markerWidth="8" markerHeight="8" orient="auto" fill="var(--blue-500)">
|
||||
<circle cx="4" cy="4" r="3.5" fill="white" stroke="var(--blue-500)"/>
|
||||
</marker>
|
||||
<marker id="arrowstart-collapsed" viewBox="0 0 10 10" refX="3" refY="5" markerWidth="8" markerHeight="8" orient="auto" fill="var(--blue-300)">
|
||||
<circle cx="4" cy="4" r="3.5" fill="white" stroke="var(--blue-300)"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<g id="connectors" fill="none">
|
||||
</g>
|
||||
</svg>
|
||||
</div>`);
|
||||
}
|
||||
|
||||
render_root_nodes(expanded_view=false) {
|
||||
let me = this;
|
||||
|
||||
frappe.call({
|
||||
method: me.method,
|
||||
args: {
|
||||
company: me.company
|
||||
}
|
||||
}).then(r => {
|
||||
if (r.message.length) {
|
||||
let expand_node = undefined;
|
||||
let node = undefined;
|
||||
|
||||
$.each(r.message, (i, data) => {
|
||||
node = new me.Node({
|
||||
id: data.id,
|
||||
parent: $('<li class="child-node"></li>').appendTo(me.$hierarchy.find('.node-children')),
|
||||
parent_id: undefined,
|
||||
image: data.image,
|
||||
name: data.name,
|
||||
title: data.title,
|
||||
expandable: true,
|
||||
connections: data.connections,
|
||||
is_root: true
|
||||
});
|
||||
|
||||
if (!expand_node && data.connections)
|
||||
expand_node = node;
|
||||
});
|
||||
|
||||
if (!expanded_view) {
|
||||
me.root_node = expand_node;
|
||||
me.expand_node(expand_node);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
expand_node(node) {
|
||||
const is_sibling = this.selected_node && this.selected_node.parent_id === node.parent_id;
|
||||
this.set_selected_node(node);
|
||||
this.show_active_path(node);
|
||||
this.collapse_previous_level_nodes(node);
|
||||
|
||||
// since the previous node collapses, all connections to that node need to be rebuilt
|
||||
// if a sibling node is clicked, connections don't need to be rebuilt
|
||||
if (!is_sibling) {
|
||||
// rebuild outgoing connections
|
||||
this.refresh_connectors(node.parent_id);
|
||||
|
||||
// rebuild incoming connections
|
||||
let grandparent = $(`#${node.parent_id}`).attr('data-parent');
|
||||
this.refresh_connectors(grandparent);
|
||||
}
|
||||
|
||||
if (node.expandable && !node.expanded) {
|
||||
return this.load_children(node);
|
||||
}
|
||||
}
|
||||
|
||||
collapse_node() {
|
||||
if (this.selected_node.expandable) {
|
||||
this.selected_node.$children.hide();
|
||||
$(`path[data-parent="${this.selected_node.id}"]`).hide();
|
||||
this.selected_node.expanded = false;
|
||||
}
|
||||
}
|
||||
|
||||
show_active_path(node) {
|
||||
// mark node parent on active path
|
||||
$(`#${node.parent_id}`).addClass('active-path');
|
||||
}
|
||||
|
||||
load_children(node, deep=false) {
|
||||
if (!deep) {
|
||||
frappe.run_serially([
|
||||
() => this.get_child_nodes(node.id),
|
||||
(child_nodes) => this.render_child_nodes(node, child_nodes)
|
||||
]);
|
||||
} else {
|
||||
frappe.run_serially([
|
||||
() => this.setup_hierarchy(),
|
||||
() => this.render_root_nodes(true),
|
||||
() => this.get_all_nodes(node.id, node.name),
|
||||
(data_list) => this.render_children_of_all_nodes(data_list)
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
get_child_nodes(node_id) {
|
||||
return new Promise(resolve => {
|
||||
frappe.call({
|
||||
method: this.method,
|
||||
args: {
|
||||
parent: node_id,
|
||||
company: this.company
|
||||
}
|
||||
}).then(r => resolve(r.message));
|
||||
});
|
||||
}
|
||||
|
||||
render_child_nodes(node, child_nodes) {
|
||||
const last_level = this.$hierarchy.find('.level:last').index();
|
||||
const current_level = $(`#${node.id}`).parent().parent().parent().index();
|
||||
|
||||
if (last_level === current_level) {
|
||||
this.$hierarchy.append(`
|
||||
<li class="level"></li>
|
||||
`);
|
||||
}
|
||||
|
||||
if (!node.$children) {
|
||||
node.$children = $('<ul class="node-children"></ul>')
|
||||
.hide()
|
||||
.appendTo(this.$hierarchy.find('.level:last'));
|
||||
|
||||
node.$children.empty();
|
||||
|
||||
if (child_nodes) {
|
||||
$.each(child_nodes, (_i, data) => {
|
||||
this.add_node(node, data);
|
||||
setTimeout(() => {
|
||||
this.add_connector(node.id, data.id);
|
||||
}, 250);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
node.$children.show();
|
||||
$(`path[data-parent="${node.id}"]`).show();
|
||||
node.expanded = true;
|
||||
}
|
||||
|
||||
get_all_nodes(node_id, node_name) {
|
||||
return new Promise(resolve => {
|
||||
frappe.call({
|
||||
method: 'erpnext.utilities.hierarchy_chart.get_all_nodes',
|
||||
args: {
|
||||
method: this.method,
|
||||
company: this.company,
|
||||
parent: node_id,
|
||||
parent_name: node_name
|
||||
},
|
||||
callback: (r) => {
|
||||
resolve(r.message);
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
render_children_of_all_nodes(data_list) {
|
||||
let entry = undefined;
|
||||
let node = undefined;
|
||||
|
||||
while (data_list.length) {
|
||||
// to avoid overlapping connectors
|
||||
entry = data_list.shift();
|
||||
node = this.nodes[entry.parent];
|
||||
if (node) {
|
||||
this.render_child_nodes_for_expanded_view(node, entry.data);
|
||||
} else {
|
||||
data_list.push(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
render_child_nodes_for_expanded_view(node, child_nodes) {
|
||||
node.$children = $('<ul class="node-children"></ul>');
|
||||
|
||||
const last_level = this.$hierarchy.find('.level:last').index();
|
||||
const node_level = $(`#${node.id}`).parent().parent().parent().index();
|
||||
|
||||
if (last_level === node_level) {
|
||||
this.$hierarchy.append(`
|
||||
<li class="level"></li>
|
||||
`);
|
||||
node.$children.appendTo(this.$hierarchy.find('.level:last'));
|
||||
} else {
|
||||
node.$children.appendTo(this.$hierarchy.find('.level:eq(' + (node_level + 1) + ')'));
|
||||
}
|
||||
|
||||
node.$children.hide().empty();
|
||||
|
||||
if (child_nodes) {
|
||||
$.each(child_nodes, (_i, data) => {
|
||||
this.add_node(node, data);
|
||||
setTimeout(() => {
|
||||
this.add_connector(node.id, data.id);
|
||||
}, 250);
|
||||
});
|
||||
}
|
||||
|
||||
node.$children.show();
|
||||
$(`path[data-parent="${node.id}"]`).show();
|
||||
node.expanded = true;
|
||||
}
|
||||
|
||||
add_node(node, data) {
|
||||
return new this.Node({
|
||||
id: data.id,
|
||||
parent: $('<li class="child-node"></li>').appendTo(node.$children),
|
||||
parent_id: node.id,
|
||||
image: data.image,
|
||||
name: data.name,
|
||||
title: data.title,
|
||||
expandable: data.expandable,
|
||||
connections: data.connections,
|
||||
children: undefined
|
||||
});
|
||||
}
|
||||
|
||||
add_connector(parent_id, child_id) {
|
||||
// using pure javascript for better performance
|
||||
const parent_node = document.querySelector(`#${parent_id}`);
|
||||
const child_node = document.querySelector(`#${child_id}`);
|
||||
|
||||
let path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
||||
|
||||
// we need to connect right side of the parent to the left side of the child node
|
||||
const pos_parent_right = {
|
||||
x: parent_node.offsetLeft + parent_node.offsetWidth,
|
||||
y: parent_node.offsetTop + parent_node.offsetHeight / 2
|
||||
};
|
||||
const pos_child_left = {
|
||||
x: child_node.offsetLeft - 5,
|
||||
y: child_node.offsetTop + child_node.offsetHeight / 2
|
||||
};
|
||||
|
||||
const connector = this.get_connector(pos_parent_right, pos_child_left);
|
||||
|
||||
path.setAttribute('d', connector);
|
||||
this.set_path_attributes(path, parent_id, child_id);
|
||||
|
||||
document.getElementById('connectors').appendChild(path);
|
||||
}
|
||||
|
||||
get_connector(pos_parent_right, pos_child_left) {
|
||||
if (pos_parent_right.y === pos_child_left.y) {
|
||||
// don't add arcs if it's a straight line
|
||||
return "M" +
|
||||
(pos_parent_right.x) + "," + (pos_parent_right.y) + " " +
|
||||
"L"+
|
||||
(pos_child_left.x) + "," + (pos_child_left.y);
|
||||
} else {
|
||||
let arc_1 = "";
|
||||
let arc_2 = "";
|
||||
let offset = 0;
|
||||
|
||||
if (pos_parent_right.y > pos_child_left.y) {
|
||||
// if child is above parent on Y axis 1st arc is anticlocwise
|
||||
// second arc is clockwise
|
||||
arc_1 = "a10,10 1 0 0 10,-10 ";
|
||||
arc_2 = "a10,10 0 0 1 10,-10 ";
|
||||
offset = 10;
|
||||
} else {
|
||||
// if child is below parent on Y axis 1st arc is clockwise
|
||||
// second arc is anticlockwise
|
||||
arc_1 = "a10,10 0 0 1 10,10 ";
|
||||
arc_2 = "a10,10 1 0 0 10,10 ";
|
||||
offset = -10;
|
||||
}
|
||||
|
||||
return "M" + (pos_parent_right.x) + "," + (pos_parent_right.y) + " " +
|
||||
"L" +
|
||||
(pos_parent_right.x + 40) + "," + (pos_parent_right.y) + " " +
|
||||
arc_1 +
|
||||
"L" +
|
||||
(pos_parent_right.x + 50) + "," + (pos_child_left.y + offset) + " " +
|
||||
arc_2 +
|
||||
"L"+
|
||||
(pos_child_left.x) + "," + (pos_child_left.y);
|
||||
}
|
||||
}
|
||||
|
||||
set_path_attributes(path, parent_id, child_id) {
|
||||
path.setAttribute("data-parent", parent_id);
|
||||
path.setAttribute("data-child", child_id);
|
||||
const parent = $(`#${parent_id}`);
|
||||
|
||||
if (parent.hasClass('active')) {
|
||||
path.setAttribute("class", "active-connector");
|
||||
path.setAttribute("marker-start", "url(#arrowstart-active)");
|
||||
path.setAttribute("marker-end", "url(#arrowhead-active)");
|
||||
} else {
|
||||
path.setAttribute("class", "collapsed-connector");
|
||||
path.setAttribute("marker-start", "url(#arrowstart-collapsed)");
|
||||
path.setAttribute("marker-end", "url(#arrowhead-collapsed)");
|
||||
}
|
||||
}
|
||||
|
||||
set_selected_node(node) {
|
||||
// remove active class from the current node
|
||||
if (this.selected_node)
|
||||
this.selected_node.$link.removeClass('active');
|
||||
|
||||
// add active class to the newly selected node
|
||||
this.selected_node = node;
|
||||
node.$link.addClass('active');
|
||||
}
|
||||
|
||||
collapse_previous_level_nodes(node) {
|
||||
let node_parent = $(`#${node.parent_id}`);
|
||||
let previous_level_nodes = node_parent.parent().parent().children('li');
|
||||
let node_card = undefined;
|
||||
|
||||
previous_level_nodes.each(function() {
|
||||
node_card = $(this).find('.node-card');
|
||||
|
||||
if (!node_card.hasClass('active-path')) {
|
||||
node_card.addClass('collapsed');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
refresh_connectors(node_parent) {
|
||||
if (!node_parent) return;
|
||||
|
||||
$(`path[data-parent="${node_parent}"]`).remove();
|
||||
|
||||
frappe.run_serially([
|
||||
() => this.get_child_nodes(node_parent),
|
||||
(child_nodes) => {
|
||||
if (child_nodes) {
|
||||
$.each(child_nodes, (_i, data) => {
|
||||
this.add_connector(node_parent, data.id);
|
||||
});
|
||||
}
|
||||
}
|
||||
]);
|
||||
}
|
||||
|
||||
setup_node_click_action(node) {
|
||||
let me = this;
|
||||
let node_element = $(`#${node.id}`);
|
||||
|
||||
node_element.click(function() {
|
||||
const is_sibling = me.selected_node.parent_id === node.parent_id;
|
||||
|
||||
if (is_sibling) {
|
||||
me.collapse_node();
|
||||
} else if (node_element.is(':visible')
|
||||
&& (node_element.hasClass('collapsed') || node_element.hasClass('active-path'))) {
|
||||
me.remove_levels_after_node(node);
|
||||
me.remove_orphaned_connectors();
|
||||
}
|
||||
|
||||
me.expand_node(node);
|
||||
});
|
||||
}
|
||||
|
||||
setup_edit_node_action(node) {
|
||||
let node_element = $(`#${node.id}`);
|
||||
let me = this;
|
||||
|
||||
node_element.find('.btn-edit-node').click(function() {
|
||||
frappe.set_route('Form', me.doctype, node.id);
|
||||
});
|
||||
}
|
||||
|
||||
remove_levels_after_node(node) {
|
||||
let level = $(`#${node.id}`).parent().parent().parent().index();
|
||||
|
||||
level = $('.hierarchy > li:eq('+ level + ')');
|
||||
level.nextAll('li').remove();
|
||||
|
||||
let nodes = level.find('.node-card');
|
||||
let node_object = undefined;
|
||||
|
||||
$.each(nodes, (_i, element) => {
|
||||
node_object = this.nodes[element.id];
|
||||
node_object.expanded = 0;
|
||||
node_object.$children = undefined;
|
||||
});
|
||||
|
||||
nodes.removeClass('collapsed active-path');
|
||||
}
|
||||
|
||||
remove_orphaned_connectors() {
|
||||
let paths = $('#connectors > path');
|
||||
$.each(paths, (_i, path) => {
|
||||
const parent = $(path).data('parent');
|
||||
const child = $(path).data('child');
|
||||
|
||||
if ($(`#${parent}`).length && $(`#${child}`).length)
|
||||
return;
|
||||
|
||||
$(path).remove();
|
||||
});
|
||||
}
|
||||
};
|
551
erpnext/public/js/hierarchy_chart/hierarchy_chart_mobile.js
Normal file
551
erpnext/public/js/hierarchy_chart/hierarchy_chart_mobile.js
Normal file
@ -0,0 +1,551 @@
|
||||
erpnext.HierarchyChartMobile = class {
|
||||
/* Options:
|
||||
- doctype
|
||||
- wrapper: wrapper for the hierarchy view
|
||||
- method:
|
||||
- to get the data for each node
|
||||
- this method should return id, name, title, image, and connections for each node
|
||||
*/
|
||||
constructor(doctype, wrapper, method) {
|
||||
this.page = wrapper.page;
|
||||
this.method = method;
|
||||
this.doctype = doctype;
|
||||
|
||||
this.page.main.css({
|
||||
'min-height': '300px',
|
||||
'max-height': '600px',
|
||||
'overflow': 'auto',
|
||||
'position': 'relative'
|
||||
});
|
||||
this.page.main.addClass('frappe-card');
|
||||
|
||||
this.nodes = {};
|
||||
this.setup_node_class();
|
||||
}
|
||||
|
||||
setup_node_class() {
|
||||
let me = this;
|
||||
this.Node = class {
|
||||
constructor({
|
||||
id, parent, parent_id, image, name, title, expandable, connections, is_root // eslint-disable-line
|
||||
}) {
|
||||
// to setup values passed via constructor
|
||||
$.extend(this, arguments[0]);
|
||||
|
||||
this.expanded = 0;
|
||||
|
||||
me.nodes[this.id] = this;
|
||||
me.make_node_element(this);
|
||||
me.setup_node_click_action(this);
|
||||
me.setup_edit_node_action(this);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
make_node_element(node) {
|
||||
let node_card = frappe.render_template('node_card', {
|
||||
id: node.id,
|
||||
name: node.name,
|
||||
title: node.title,
|
||||
image: node.image,
|
||||
parent: node.parent_id,
|
||||
connections: node.connections,
|
||||
is_mobile: true
|
||||
});
|
||||
|
||||
node.parent.append(node_card);
|
||||
node.$link = $(`#${node.id}`);
|
||||
node.$link.addClass('mobile-node');
|
||||
}
|
||||
|
||||
show() {
|
||||
frappe.breadcrumbs.add('HR');
|
||||
|
||||
let me = this;
|
||||
if ($(`[data-fieldname="company"]`).length) return;
|
||||
|
||||
let company = this.page.add_field({
|
||||
fieldtype: 'Link',
|
||||
options: 'Company',
|
||||
fieldname: 'company',
|
||||
placeholder: __('Select Company'),
|
||||
default: frappe.defaults.get_default('company'),
|
||||
only_select: true,
|
||||
reqd: 1,
|
||||
change: () => {
|
||||
me.company = undefined;
|
||||
|
||||
if (company.get_value() && me.company != company.get_value()) {
|
||||
me.company = company.get_value();
|
||||
|
||||
// svg for connectors
|
||||
me.make_svg_markers();
|
||||
|
||||
if (me.$sibling_group)
|
||||
me.$sibling_group.remove();
|
||||
|
||||
// setup sibling group wrapper
|
||||
me.$sibling_group = $(`<div class="sibling-group mt-4 mb-4"></div>`);
|
||||
me.page.main.append(me.$sibling_group);
|
||||
|
||||
me.setup_hierarchy();
|
||||
me.render_root_nodes();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
company.refresh();
|
||||
$(`[data-fieldname="company"]`).trigger('change');
|
||||
}
|
||||
|
||||
make_svg_markers() {
|
||||
$('#arrows').remove();
|
||||
|
||||
this.page.main.prepend(`
|
||||
<svg id="arrows" width="100%" height="100%">
|
||||
<defs>
|
||||
<marker id="arrowhead-active" viewBox="0 0 10 10" refX="3" refY="5" markerWidth="6" markerHeight="6" orient="auto" fill="var(--blue-500)">
|
||||
<path d="M 0 0 L 10 5 L 0 10 z"></path>
|
||||
</marker>
|
||||
<marker id="arrowhead-collapsed" viewBox="0 0 10 10" refX="3" refY="5" markerWidth="6" markerHeight="6" orient="auto" fill="var(--blue-300)">
|
||||
<path d="M 0 0 L 10 5 L 0 10 z"></path>
|
||||
</marker>
|
||||
|
||||
<marker id="arrowstart-active" viewBox="0 0 10 10" refX="3" refY="5" markerWidth="8" markerHeight="8" orient="auto" fill="var(--blue-500)">
|
||||
<circle cx="4" cy="4" r="3.5" fill="white" stroke="var(--blue-500)"/>
|
||||
</marker>
|
||||
<marker id="arrowstart-collapsed" viewBox="0 0 10 10" refX="3" refY="5" markerWidth="8" markerHeight="8" orient="auto" fill="var(--blue-300)">
|
||||
<circle cx="4" cy="4" r="3.5" fill="white" stroke="var(--blue-300)"/>
|
||||
</marker>
|
||||
</defs>
|
||||
<g id="connectors" fill="none">
|
||||
</g>
|
||||
</svg>`);
|
||||
}
|
||||
|
||||
setup_hierarchy() {
|
||||
$(`#connectors`).empty();
|
||||
if (this.$hierarchy)
|
||||
this.$hierarchy.remove();
|
||||
|
||||
if (this.$sibling_group)
|
||||
this.$sibling_group.empty();
|
||||
|
||||
this.$hierarchy = $(
|
||||
`<ul class="hierarchy-mobile">
|
||||
<li class="root-level level"></li>
|
||||
</ul>`);
|
||||
|
||||
this.page.main.append(this.$hierarchy);
|
||||
}
|
||||
|
||||
render_root_nodes() {
|
||||
let me = this;
|
||||
|
||||
frappe.call({
|
||||
method: me.method,
|
||||
args: {
|
||||
company: me.company
|
||||
},
|
||||
}).then(r => {
|
||||
if (r.message.length) {
|
||||
let root_level = me.$hierarchy.find('.root-level');
|
||||
root_level.empty();
|
||||
|
||||
$.each(r.message, (_i, data) => {
|
||||
return new me.Node({
|
||||
id: data.id,
|
||||
parent: root_level,
|
||||
parent_id: undefined,
|
||||
image: data.image,
|
||||
name: data.name,
|
||||
title: data.title,
|
||||
expandable: true,
|
||||
connections: data.connections,
|
||||
is_root: true
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
expand_node(node) {
|
||||
const is_same_node = (this.selected_node && this.selected_node.id === node.id);
|
||||
this.set_selected_node(node);
|
||||
this.show_active_path(node);
|
||||
|
||||
if (this.$sibling_group) {
|
||||
const sibling_parent = this.$sibling_group.find('.node-group').attr('data-parent');
|
||||
if (node.parent_id !== undefined && node.parent_id != sibling_parent)
|
||||
this.$sibling_group.empty();
|
||||
}
|
||||
|
||||
if (!is_same_node) {
|
||||
// since the previous/parent node collapses, all connections to that node need to be rebuilt
|
||||
// rebuild outgoing connections of parent
|
||||
this.refresh_connectors(node.parent_id, node.id);
|
||||
|
||||
// rebuild incoming connections of parent
|
||||
let grandparent = $(`#${node.parent_id}`).attr('data-parent');
|
||||
this.refresh_connectors(grandparent, node.parent_id);
|
||||
}
|
||||
|
||||
if (node.expandable && !node.expanded) {
|
||||
return this.load_children(node);
|
||||
}
|
||||
}
|
||||
|
||||
collapse_node() {
|
||||
let node = this.selected_node;
|
||||
if (node.expandable && node.$children) {
|
||||
node.$children.hide();
|
||||
node.expanded = 0;
|
||||
|
||||
// add a collapsed level to show the collapsed parent
|
||||
// and a button beside it to move to that level
|
||||
let node_parent = node.$link.parent();
|
||||
node_parent.prepend(
|
||||
`<div class="collapsed-level d-flex flex-row"></div>`
|
||||
);
|
||||
|
||||
node_parent
|
||||
.find('.collapsed-level')
|
||||
.append(node.$link);
|
||||
|
||||
frappe.run_serially([
|
||||
() => this.get_child_nodes(node.parent_id, node.id),
|
||||
(child_nodes) => this.get_node_group(child_nodes, node.parent_id),
|
||||
(node_group) => node_parent.find('.collapsed-level').append(node_group),
|
||||
() => this.setup_node_group_action()
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
show_active_path(node) {
|
||||
// mark node parent on active path
|
||||
$(`#${node.parent_id}`).addClass('active-path');
|
||||
}
|
||||
|
||||
load_children(node) {
|
||||
frappe.run_serially([
|
||||
() => this.get_child_nodes(node.id),
|
||||
(child_nodes) => this.render_child_nodes(node, child_nodes)
|
||||
]);
|
||||
}
|
||||
|
||||
get_child_nodes(node_id, exclude_node=null) {
|
||||
let me = this;
|
||||
return new Promise(resolve => {
|
||||
frappe.call({
|
||||
method: this.method,
|
||||
args: {
|
||||
parent: node_id,
|
||||
company: me.company,
|
||||
exclude_node: exclude_node
|
||||
}
|
||||
}).then(r => resolve(r.message));
|
||||
});
|
||||
}
|
||||
|
||||
render_child_nodes(node, child_nodes) {
|
||||
if (!node.$children) {
|
||||
node.$children = $('<ul class="node-children"></ul>')
|
||||
.hide()
|
||||
.appendTo(node.$link.parent());
|
||||
|
||||
node.$children.empty();
|
||||
|
||||
if (child_nodes) {
|
||||
$.each(child_nodes, (_i, data) => {
|
||||
this.add_node(node, data);
|
||||
$(`#${data.id}`).addClass('active-child');
|
||||
|
||||
setTimeout(() => {
|
||||
this.add_connector(node.id, data.id);
|
||||
}, 250);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
node.$children.show();
|
||||
node.expanded = 1;
|
||||
}
|
||||
|
||||
add_node(node, data) {
|
||||
var $li = $('<li class="child-node"></li>');
|
||||
|
||||
return new this.Node({
|
||||
id: data.id,
|
||||
parent: $li.appendTo(node.$children),
|
||||
parent_id: node.id,
|
||||
image: data.image,
|
||||
name: data.name,
|
||||
title: data.title,
|
||||
expandable: data.expandable,
|
||||
connections: data.connections,
|
||||
children: undefined
|
||||
});
|
||||
}
|
||||
|
||||
add_connector(parent_id, child_id) {
|
||||
const parent_node = document.querySelector(`#${parent_id}`);
|
||||
const child_node = document.querySelector(`#${child_id}`);
|
||||
|
||||
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
||||
|
||||
let connector = undefined;
|
||||
|
||||
if ($(`#${parent_id}`).hasClass('active')) {
|
||||
connector = this.get_connector_for_active_node(parent_node, child_node);
|
||||
} else if ($(`#${parent_id}`).hasClass('active-path')) {
|
||||
connector = this.get_connector_for_collapsed_node(parent_node, child_node);
|
||||
}
|
||||
|
||||
path.setAttribute('d', connector);
|
||||
this.set_path_attributes(path, parent_id, child_id);
|
||||
|
||||
document.getElementById('connectors').appendChild(path);
|
||||
}
|
||||
|
||||
get_connector_for_active_node(parent_node, child_node) {
|
||||
// we need to connect the bottom left of the parent to the left side of the child node
|
||||
let pos_parent_bottom = {
|
||||
x: parent_node.offsetLeft + 20,
|
||||
y: parent_node.offsetTop + parent_node.offsetHeight
|
||||
};
|
||||
let pos_child_left = {
|
||||
x: child_node.offsetLeft - 5,
|
||||
y: child_node.offsetTop + child_node.offsetHeight / 2
|
||||
};
|
||||
|
||||
let connector =
|
||||
"M" +
|
||||
(pos_parent_bottom.x) + "," + (pos_parent_bottom.y) + " " +
|
||||
"L" +
|
||||
(pos_parent_bottom.x) + "," + (pos_child_left.y - 10) + " " +
|
||||
"a10,10 1 0 0 10,10 " +
|
||||
"L" +
|
||||
(pos_child_left.x) + "," + (pos_child_left.y);
|
||||
|
||||
return connector;
|
||||
}
|
||||
|
||||
get_connector_for_collapsed_node(parent_node, child_node) {
|
||||
// we need to connect the bottom left of the parent to the top left of the child node
|
||||
let pos_parent_bottom = {
|
||||
x: parent_node.offsetLeft + 20,
|
||||
y: parent_node.offsetTop + parent_node.offsetHeight
|
||||
};
|
||||
let pos_child_top = {
|
||||
x: child_node.offsetLeft + 20,
|
||||
y: child_node.offsetTop
|
||||
};
|
||||
|
||||
let connector =
|
||||
"M" +
|
||||
(pos_parent_bottom.x) + "," + (pos_parent_bottom.y) + " " +
|
||||
"L" +
|
||||
(pos_child_top.x) + "," + (pos_child_top.y);
|
||||
|
||||
return connector;
|
||||
}
|
||||
|
||||
set_path_attributes(path, parent_id, child_id) {
|
||||
path.setAttribute("data-parent", parent_id);
|
||||
path.setAttribute("data-child", child_id);
|
||||
const parent = $(`#${parent_id}`);
|
||||
|
||||
if (parent.hasClass('active')) {
|
||||
path.setAttribute("class", "active-connector");
|
||||
path.setAttribute("marker-start", "url(#arrowstart-active)");
|
||||
path.setAttribute("marker-end", "url(#arrowhead-active)");
|
||||
} else if (parent.hasClass('active-path')) {
|
||||
path.setAttribute("class", "collapsed-connector");
|
||||
}
|
||||
}
|
||||
|
||||
set_selected_node(node) {
|
||||
// remove .active class from the current node
|
||||
if (this.selected_node)
|
||||
this.selected_node.$link.removeClass('active');
|
||||
|
||||
// add active class to the newly selected node
|
||||
this.selected_node = node;
|
||||
node.$link.addClass('active');
|
||||
}
|
||||
|
||||
setup_node_click_action(node) {
|
||||
let me = this;
|
||||
let node_element = $(`#${node.id}`);
|
||||
|
||||
node_element.click(function() {
|
||||
let el = undefined;
|
||||
|
||||
if (node.is_root) {
|
||||
el = $(this).detach();
|
||||
me.$hierarchy.empty();
|
||||
$(`#connectors`).empty();
|
||||
me.add_node_to_hierarchy(el, node);
|
||||
} else if (node_element.is(':visible') && node_element.hasClass('active-path')) {
|
||||
me.remove_levels_after_node(node);
|
||||
me.remove_orphaned_connectors();
|
||||
} else {
|
||||
el = $(this).detach();
|
||||
me.add_node_to_hierarchy(el, node);
|
||||
me.collapse_node();
|
||||
}
|
||||
|
||||
me.expand_node(node);
|
||||
});
|
||||
}
|
||||
|
||||
setup_edit_node_action(node) {
|
||||
let node_element = $(`#${node.id}`);
|
||||
let me = this;
|
||||
|
||||
node_element.find('.btn-edit-node').click(function() {
|
||||
frappe.set_route('Form', me.doctype, node.id);
|
||||
});
|
||||
}
|
||||
|
||||
setup_node_group_action() {
|
||||
let me = this;
|
||||
|
||||
$('.node-group').on('click', function() {
|
||||
let parent = $(this).attr('data-parent');
|
||||
if (parent === 'undefined') {
|
||||
me.setup_hierarchy();
|
||||
me.render_root_nodes();
|
||||
} else {
|
||||
me.expand_sibling_group_node(parent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
add_node_to_hierarchy(node_element, node) {
|
||||
this.$hierarchy.append(`<li class="level"></li>`);
|
||||
node_element.removeClass('active-child active-path');
|
||||
this.$hierarchy.find('.level:last').append(node_element);
|
||||
|
||||
let node_object = this.nodes[node.id];
|
||||
node_object.expanded = 0;
|
||||
node_object.$children = undefined;
|
||||
this.nodes[node.id] = node_object;
|
||||
}
|
||||
|
||||
get_node_group(nodes, parent, collapsed=true) {
|
||||
let limit = 2;
|
||||
const display_nodes = nodes.slice(0, limit);
|
||||
const extra_nodes = nodes.slice(limit);
|
||||
|
||||
let html = display_nodes.map(node =>
|
||||
this.get_avatar(node)
|
||||
).join('');
|
||||
|
||||
if (extra_nodes.length === 1) {
|
||||
let node = extra_nodes[0];
|
||||
html += this.get_avatar(node);
|
||||
} else if (extra_nodes.length > 1) {
|
||||
html = `
|
||||
${html}
|
||||
<span class="avatar avatar-small">
|
||||
<div class="avatar-frame standard-image avatar-extra-count"
|
||||
title="${extra_nodes.map(node => node.name).join(', ')}">
|
||||
+${extra_nodes.length}
|
||||
</div>
|
||||
</span>
|
||||
`;
|
||||
}
|
||||
|
||||
if (html) {
|
||||
const $node_group =
|
||||
$(`<div class="node-group card cursor-pointer" data-parent=${parent}>
|
||||
<div class="avatar-group right overlap">
|
||||
${html}
|
||||
</div>
|
||||
</div>`);
|
||||
|
||||
if (collapsed)
|
||||
$node_group.addClass('collapsed');
|
||||
|
||||
return $node_group;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
get_avatar(node) {
|
||||
return `<span class="avatar avatar-small" title="${node.name}">
|
||||
<span class="avatar-frame" src=${node.image} style="background-image: url(${node.image})"></span>
|
||||
</span>`;
|
||||
}
|
||||
|
||||
expand_sibling_group_node(parent) {
|
||||
let node_object = this.nodes[parent];
|
||||
let node = node_object.$link;
|
||||
|
||||
node.removeClass('active-child active-path');
|
||||
node_object.expanded = 0;
|
||||
node_object.$children = undefined;
|
||||
this.nodes[node.id] = node_object;
|
||||
|
||||
// show parent's siblings and expand parent node
|
||||
frappe.run_serially([
|
||||
() => this.get_child_nodes(node_object.parent_id, node_object.id),
|
||||
(child_nodes) => this.get_node_group(child_nodes, node_object.parent_id, false),
|
||||
(node_group) => {
|
||||
if (node_group)
|
||||
this.$sibling_group.empty().append(node_group);
|
||||
},
|
||||
() => this.setup_node_group_action(),
|
||||
() => this.reattach_and_expand_node(node, node_object)
|
||||
]);
|
||||
}
|
||||
|
||||
reattach_and_expand_node(node, node_object) {
|
||||
var el = node.detach();
|
||||
|
||||
this.$hierarchy.empty().append(`
|
||||
<li class="level"></li>
|
||||
`);
|
||||
this.$hierarchy.find('.level').append(el);
|
||||
$(`#connectors`).empty();
|
||||
this.expand_node(node_object);
|
||||
}
|
||||
|
||||
remove_levels_after_node(node) {
|
||||
let level = $(`#${node.id}`).parent().parent().index();
|
||||
|
||||
level = $('.hierarchy-mobile > li:eq('+ level + ')');
|
||||
level.nextAll('li').remove();
|
||||
|
||||
let node_object = this.nodes[node.id];
|
||||
let current_node = level.find(`#${node.id}`).detach();
|
||||
current_node.removeClass('active-child active-path');
|
||||
|
||||
node_object.expanded = 0;
|
||||
node_object.$children = undefined;
|
||||
|
||||
level.empty().append(current_node);
|
||||
}
|
||||
|
||||
remove_orphaned_connectors() {
|
||||
let paths = $('#connectors > path');
|
||||
$.each(paths, (_i, path) => {
|
||||
const parent = $(path).data('parent');
|
||||
const child = $(path).data('child');
|
||||
|
||||
if ($(`#${parent}`).length && $(`#${child}`).length)
|
||||
return;
|
||||
|
||||
$(path).remove();
|
||||
});
|
||||
}
|
||||
|
||||
refresh_connectors(node_parent, node_id) {
|
||||
if (!node_parent) return;
|
||||
|
||||
$(`path[data-parent="${node_parent}"]`).remove();
|
||||
this.add_connector(node_parent, node_id);
|
||||
}
|
||||
};
|
33
erpnext/public/js/templates/node_card.html
Normal file
33
erpnext/public/js/templates/node_card.html
Normal file
@ -0,0 +1,33 @@
|
||||
<div class="node-card card cursor-pointer" id="{%= id %}" data-parent="{%= parent %}">
|
||||
<div class="node-meta d-flex flex-row">
|
||||
<div class="mr-3">
|
||||
<span class="avatar node-image" title="{{ name }}">
|
||||
<span class="avatar-frame" src={{image}} style="background-image: url(\'{%= image %}\')"></span>
|
||||
</span>
|
||||
</div>
|
||||
<div>
|
||||
<div class="node-name d-flex flex-row mb-1">
|
||||
<span class="ellipsis">{{ name }}</span>
|
||||
<div class="btn-xs btn-edit-node d-flex flex-row">
|
||||
<a class="node-edit-icon">{{ frappe.utils.icon("edit", "xs") }}</a>
|
||||
<span class="edit-chart-node text-xs">{{ __("Edit") }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="node-info d-flex flex-row mb-1">
|
||||
<div class="node-title text-muted ellipsis">{{ title }}</div>
|
||||
|
||||
{% if is_mobile %}
|
||||
<div class="node-connections text-muted ml-2 ellipsis">
|
||||
· {{ connections }} <span class="fa fa-level-down"></span>
|
||||
</div>
|
||||
{% else %}
|
||||
{% if connections == 1 %}
|
||||
<div class="node-connections text-muted ml-2 ellipsis">· {{ connections }} Connection</div>
|
||||
{% else %}
|
||||
<div class="node-connections text-muted ml-2 ellipsis">· {{ connections }} Connections</div>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -76,6 +76,7 @@ erpnext.utils.get_party_details = function(frm, method, args, callback) {
|
||||
|
||||
if (args) {
|
||||
args.posting_date = frm.doc.posting_date || frm.doc.transaction_date;
|
||||
args.fetch_payment_terms_template = cint(!frm.doc.ignore_default_payment_terms_template);
|
||||
}
|
||||
}
|
||||
if (!args || !args.party) return;
|
||||
|
311
erpnext/public/scss/hierarchy_chart.scss
Normal file
311
erpnext/public/scss/hierarchy_chart.scss
Normal file
@ -0,0 +1,311 @@
|
||||
.node-card {
|
||||
background: white;
|
||||
stroke: 1px solid var(--gray-200);
|
||||
box-shadow: var(--shadow-base);
|
||||
border-radius: 0.5rem;
|
||||
padding: 0.75rem;
|
||||
margin-left: 3rem;
|
||||
width: 18rem;
|
||||
overflow: hidden;
|
||||
|
||||
.btn-edit-node {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.edit-chart-node {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.node-edit-icon {
|
||||
display: none;
|
||||
}
|
||||
}
|
||||
|
||||
.node-card.exported {
|
||||
box-shadow: none
|
||||
}
|
||||
|
||||
.node-image {
|
||||
width: 3.0rem;
|
||||
height: 3.0rem;
|
||||
}
|
||||
|
||||
.node-name {
|
||||
font-size: 1rem;
|
||||
line-height: 1.72;
|
||||
}
|
||||
|
||||
.node-title {
|
||||
font-size: 0.75rem;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.node-info {
|
||||
width: 12.7rem;
|
||||
}
|
||||
|
||||
.node-connections {
|
||||
font-size: 0.75rem;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.node-card.active {
|
||||
background: var(--blue-50);
|
||||
border: 1px solid var(--blue-500);
|
||||
box-shadow: var(--shadow-md);
|
||||
border-radius: 0.5rem;
|
||||
padding: 0.75rem;
|
||||
width: 18rem;
|
||||
|
||||
.btn-edit-node {
|
||||
display: flex;
|
||||
background: var(--blue-100);
|
||||
color: var(--blue-500);
|
||||
padding: .25rem .5rem;
|
||||
font-size: .75rem;
|
||||
justify-content: center;
|
||||
box-shadow: var(--shadow-sm);
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.edit-chart-node {
|
||||
display: block;
|
||||
margin-right: 0.25rem;
|
||||
}
|
||||
|
||||
.node-edit-icon {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.node-edit-icon > .icon{
|
||||
stroke: var(--blue-500);
|
||||
}
|
||||
|
||||
.node-name {
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
margin-bottom: 2px;
|
||||
width: 12.2rem;
|
||||
}
|
||||
}
|
||||
|
||||
.node-card.active-path {
|
||||
background: var(--blue-100);
|
||||
border: 1px solid var(--blue-300);
|
||||
box-shadow: var(--shadow-sm);
|
||||
border-radius: 0.5rem;
|
||||
padding: 0.75rem;
|
||||
width: 15rem;
|
||||
height: 3.0rem;
|
||||
|
||||
.btn-edit-node {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.edit-chart-node {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.node-edit-icon {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.node-info {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.node-title {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.node-connections {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.node-name {
|
||||
font-size: 0.85rem;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.node-image {
|
||||
width: 1.5rem;
|
||||
height: 1.5rem;
|
||||
}
|
||||
|
||||
.node-meta {
|
||||
align-items: baseline;
|
||||
}
|
||||
}
|
||||
|
||||
.node-card.collapsed {
|
||||
background: white;
|
||||
stroke: 1px solid var(--gray-200);
|
||||
box-shadow: var(--shadow-sm);
|
||||
border-radius: 0.5rem;
|
||||
padding: 0.75rem;
|
||||
width: 15rem;
|
||||
height: 3.0rem;
|
||||
|
||||
.btn-edit-node {
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.edit-chart-node {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.node-edit-icon {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.node-info {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.node-title {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.node-connections {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.node-name {
|
||||
font-size: 0.85rem;
|
||||
line-height: 1.35;
|
||||
}
|
||||
|
||||
.node-image {
|
||||
width: 1.5rem;
|
||||
height: 1.5rem;
|
||||
}
|
||||
|
||||
.node-meta {
|
||||
align-items: baseline;
|
||||
}
|
||||
}
|
||||
|
||||
// horizontal hierarchy tree view
|
||||
#hierarchy-chart-wrapper {
|
||||
padding-top: 30px;
|
||||
|
||||
#arrows {
|
||||
margin-top: -80px;
|
||||
}
|
||||
}
|
||||
|
||||
.hierarchy {
|
||||
display: flex;
|
||||
}
|
||||
|
||||
.hierarchy li {
|
||||
list-style-type: none;
|
||||
}
|
||||
|
||||
.child-node {
|
||||
margin: 0px 0px 16px 0px;
|
||||
}
|
||||
|
||||
.level {
|
||||
margin-right: 8px;
|
||||
align-items: flex-start;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
#arrows {
|
||||
position: absolute;
|
||||
overflow: visible;
|
||||
}
|
||||
|
||||
.active-connector {
|
||||
stroke: var(--blue-500);
|
||||
}
|
||||
|
||||
.collapsed-connector {
|
||||
stroke: var(--blue-300);
|
||||
}
|
||||
|
||||
// mobile
|
||||
|
||||
.hierarchy-mobile {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
padding-top: 10px;
|
||||
padding-left: 0px;
|
||||
}
|
||||
|
||||
.hierarchy-mobile li {
|
||||
list-style-type: none;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-end;
|
||||
}
|
||||
|
||||
.mobile-node {
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.mobile-node.active-path {
|
||||
width: 12.25rem;
|
||||
}
|
||||
|
||||
.active-child {
|
||||
width: 15.5rem;
|
||||
}
|
||||
|
||||
.mobile-node .node-connections {
|
||||
max-width: 80px;
|
||||
}
|
||||
|
||||
.hierarchy-mobile .node-children {
|
||||
margin-top: 16px;
|
||||
}
|
||||
|
||||
.root-level .node-card {
|
||||
margin: 0 0 16px;
|
||||
}
|
||||
|
||||
// node group
|
||||
|
||||
.collapsed-level {
|
||||
margin-bottom: 16px;
|
||||
width: 18rem;
|
||||
}
|
||||
|
||||
.node-group {
|
||||
background: white;
|
||||
border: 1px solid var(--gray-300);
|
||||
box-shadow: var(--shadow-sm);
|
||||
border-radius: 0.5rem;
|
||||
padding: 0.75rem;
|
||||
width: 18rem;
|
||||
height: 3rem;
|
||||
overflow: hidden;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.node-group .avatar-group {
|
||||
margin-left: 0px;
|
||||
}
|
||||
|
||||
.node-group .avatar-extra-count {
|
||||
background-color: var(--blue-100);
|
||||
color: var(--blue-500);
|
||||
}
|
||||
|
||||
.node-group .avatar-frame {
|
||||
width: 1.5rem;
|
||||
height: 1.5rem;
|
||||
}
|
||||
|
||||
.node-group.collapsed {
|
||||
width: 5rem;
|
||||
margin-left: 12px;
|
||||
}
|
||||
|
||||
.sibling-group {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
}
|
@ -457,7 +457,7 @@ def make_custom_fields(update=True):
|
||||
depends_on='eval:in_list(["Registered Regular", "SEZ", "Overseas", "Deemed Export"], doc.gst_category) && doc.irn_cancelled === 0'),
|
||||
|
||||
dict(fieldname='irn_cancelled', label='IRN Cancelled', fieldtype='Check', no_copy=1, print_hide=1,
|
||||
depends_on='eval:(doc.irn_cancelled === 1)', read_only=1, allow_on_submit=1, insert_after='customer'),
|
||||
depends_on='eval: doc.irn', allow_on_submit=1, insert_after='customer'),
|
||||
|
||||
dict(fieldname='eway_bill_validity', label='E-Way Bill Validity', fieldtype='Data', no_copy=1, print_hide=1,
|
||||
depends_on='ewaybill', read_only=1, allow_on_submit=1, insert_after='ewaybill'),
|
||||
@ -985,4 +985,4 @@ def create_gratuity_rule():
|
||||
|
||||
def update_accounts_settings_for_taxes():
|
||||
if frappe.db.count('Company') == 1:
|
||||
frappe.db.set_value('Accounts Settings', None, "add_taxes_from_item_tax_template", 0)
|
||||
frappe.db.set_value('Accounts Settings', None, "add_taxes_from_item_tax_template", 0)
|
||||
|
@ -851,7 +851,7 @@ def get_depreciation_amount(asset, depreciable_value, row):
|
||||
# if its the first depreciation
|
||||
if depreciable_value == asset.gross_purchase_amount:
|
||||
# as per IT act, if the asset is purchased in the 2nd half of fiscal year, then rate is divided by 2
|
||||
diff = date_diff(asset.available_for_use_date, row.depreciation_start_date)
|
||||
diff = date_diff(row.depreciation_start_date, asset.available_for_use_date)
|
||||
if diff <= 180:
|
||||
rate_of_depreciation = rate_of_depreciation / 2
|
||||
frappe.msgprint(
|
||||
|
@ -157,9 +157,7 @@ class Customer(TransactionBase):
|
||||
'''If Customer created from Lead, update lead status to "Converted"
|
||||
update Customer link in Quotation, Opportunity'''
|
||||
if self.lead_name:
|
||||
lead = frappe.get_doc('Lead', self.lead_name)
|
||||
lead.status = 'Converted'
|
||||
lead.save()
|
||||
frappe.db.set_value("Lead", self.lead_name, "status", "Converted")
|
||||
|
||||
def create_lead_address_contact(self):
|
||||
if self.lead_name:
|
||||
|
@ -670,6 +670,7 @@ def make_sales_invoice(source_name, target_doc=None, ignore_permissions=False):
|
||||
"party_account_currency": "party_account_currency",
|
||||
"payment_terms_template": "payment_terms_template"
|
||||
},
|
||||
"field_no_map": ["payment_terms_template"],
|
||||
"validation": {
|
||||
"docstatus": ["=", 1]
|
||||
}
|
||||
@ -693,6 +694,10 @@ def make_sales_invoice(source_name, target_doc=None, ignore_permissions=False):
|
||||
}
|
||||
}, target_doc, postprocess, ignore_permissions=ignore_permissions)
|
||||
|
||||
automatically_fetch_payment_terms = cint(frappe.db.get_single_value('Accounts Settings', 'automatically_fetch_payment_terms'))
|
||||
if automatically_fetch_payment_terms:
|
||||
doclist.set_payment_schedule()
|
||||
|
||||
return doclist
|
||||
|
||||
@frappe.whitelist()
|
||||
|
@ -5,7 +5,7 @@ import json
|
||||
import unittest
|
||||
import frappe
|
||||
import frappe.permissions
|
||||
from frappe.utils import flt, add_days, nowdate
|
||||
from frappe.utils import flt, add_days, nowdate, getdate
|
||||
from frappe.core.doctype.user_permission.test_user_permission import create_user
|
||||
from erpnext.selling.doctype.sales_order.sales_order \
|
||||
import make_material_request, make_delivery_note, make_sales_invoice, WarehouseRequired
|
||||
@ -1229,7 +1229,38 @@ class TestSalesOrder(unittest.TestCase):
|
||||
|
||||
self.assertRaises(frappe.ValidationError, so.cancel)
|
||||
|
||||
def test_payment_terms_are_fetched_when_creating_sales_invoice(self):
|
||||
from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_terms_template
|
||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
||||
|
||||
automatically_fetch_payment_terms()
|
||||
|
||||
so = make_sales_order(uom="Nos", do_not_save=1)
|
||||
create_payment_terms_template()
|
||||
so.payment_terms_template = 'Test Receivable Template'
|
||||
so.submit()
|
||||
|
||||
si = create_sales_invoice(qty=10, do_not_save=1)
|
||||
si.items[0].sales_order = so.name
|
||||
si.items[0].so_detail = so.items[0].name
|
||||
si.insert()
|
||||
|
||||
self.assertEqual(so.payment_terms_template, si.payment_terms_template)
|
||||
compare_payment_schedules(self, so, si)
|
||||
|
||||
automatically_fetch_payment_terms(enable=0)
|
||||
|
||||
def automatically_fetch_payment_terms(enable=1):
|
||||
accounts_settings = frappe.get_doc("Accounts Settings")
|
||||
accounts_settings.automatically_fetch_payment_terms = enable
|
||||
accounts_settings.save()
|
||||
|
||||
def compare_payment_schedules(doc, doc1, doc2):
|
||||
for index, schedule in enumerate(doc1.get('payment_schedule')):
|
||||
doc.assertEqual(schedule.payment_term, doc2.payment_schedule[index].payment_term)
|
||||
doc.assertEqual(getdate(schedule.due_date), doc2.payment_schedule[index].due_date)
|
||||
doc.assertEqual(schedule.invoice_portion, doc2.payment_schedule[index].invoice_portion)
|
||||
doc.assertEqual(schedule.payment_amount, doc2.payment_schedule[index].payment_amount)
|
||||
|
||||
def make_sales_order(**args):
|
||||
so = frappe.new_doc("Sales Order")
|
||||
|
@ -108,6 +108,9 @@ class Company(NestedSet):
|
||||
frappe.flags.country_change = True
|
||||
self.create_default_accounts()
|
||||
self.create_default_warehouses()
|
||||
|
||||
if not frappe.db.get_value("Cost Center", {"is_group": 0, "company": self.name}):
|
||||
self.create_default_cost_center()
|
||||
|
||||
if frappe.flags.country_change:
|
||||
install_country_fixtures(self.name, self.country)
|
||||
@ -117,9 +120,6 @@ class Company(NestedSet):
|
||||
from erpnext.setup.setup_wizard.operations.install_fixtures import install_post_company_fixtures
|
||||
install_post_company_fixtures(frappe._dict({'company_name': self.name}))
|
||||
|
||||
if not frappe.db.get_value("Cost Center", {"is_group": 0, "company": self.name}):
|
||||
self.create_default_cost_center()
|
||||
|
||||
if not frappe.local.flags.ignore_chart_of_accounts:
|
||||
self.set_default_accounts()
|
||||
if self.default_cash_account:
|
||||
|
@ -124,7 +124,8 @@ def make_taxes_and_charges_template(company_name, doctype, template):
|
||||
account_data = tax_row.get('account_head')
|
||||
tax_row_defaults = {
|
||||
'category': 'Total',
|
||||
'charge_type': 'On Net Total'
|
||||
'charge_type': 'On Net Total',
|
||||
'cost_center': frappe.db.get_value('Company', company_name, 'cost_center')
|
||||
}
|
||||
|
||||
if doctype == 'Purchase Taxes and Charges Template':
|
||||
|
@ -503,6 +503,10 @@ def make_sales_invoice(source_name, target_doc=None):
|
||||
}
|
||||
}, target_doc, set_missing_values)
|
||||
|
||||
automatically_fetch_payment_terms = cint(frappe.db.get_single_value('Accounts Settings', 'automatically_fetch_payment_terms'))
|
||||
if automatically_fetch_payment_terms:
|
||||
doc.set_payment_schedule()
|
||||
|
||||
return doc
|
||||
|
||||
@frappe.whitelist()
|
||||
|
@ -17,7 +17,8 @@ from erpnext.stock.doctype.stock_entry.test_stock_entry \
|
||||
from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos, SerialNoWarehouseError
|
||||
from erpnext.stock.doctype.stock_reconciliation.test_stock_reconciliation \
|
||||
import create_stock_reconciliation, set_valuation_method
|
||||
from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order, create_dn_against_so
|
||||
from erpnext.selling.doctype.sales_order.test_sales_order \
|
||||
import make_sales_order, create_dn_against_so, automatically_fetch_payment_terms, compare_payment_schedules
|
||||
from erpnext.accounts.doctype.account.test_account import get_inventory_account
|
||||
from erpnext.stock.doctype.warehouse.test_warehouse import get_warehouse
|
||||
from erpnext.stock.doctype.item.test_item import make_item
|
||||
@ -759,6 +760,32 @@ class TestDeliveryNote(unittest.TestCase):
|
||||
|
||||
self.assertTrue("TESTBATCH" in dn.packed_items[0].batch_no, "Batch number not added in packed item")
|
||||
|
||||
def test_payment_terms_are_fetched_when_creating_sales_invoice(self):
|
||||
from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_terms_template
|
||||
from erpnext.accounts.doctype.sales_invoice.test_sales_invoice import create_sales_invoice
|
||||
|
||||
automatically_fetch_payment_terms()
|
||||
|
||||
so = make_sales_order(uom="Nos", do_not_save=1)
|
||||
create_payment_terms_template()
|
||||
so.payment_terms_template = 'Test Receivable Template'
|
||||
so.submit()
|
||||
|
||||
dn = create_dn_against_so(so.name, delivered_qty=10)
|
||||
|
||||
si = create_sales_invoice(qty=10, do_not_save=1)
|
||||
si.items[0].delivery_note= dn.name
|
||||
si.items[0].dn_detail = dn.items[0].name
|
||||
si.items[0].sales_order = so.name
|
||||
si.items[0].so_detail = so.items[0].name
|
||||
|
||||
si.insert()
|
||||
si.submit()
|
||||
|
||||
self.assertEqual(so.payment_terms_template, si.payment_terms_template)
|
||||
compare_payment_schedules(self, so, si)
|
||||
|
||||
automatically_fetch_payment_terms(enable=0)
|
||||
|
||||
def create_delivery_note(**args):
|
||||
dn = frappe.new_doc("Delivery Note")
|
||||
|
@ -260,6 +260,17 @@ $.extend(erpnext.item, {
|
||||
}
|
||||
}
|
||||
|
||||
frm.fields_dict["item_defaults"].grid.get_field("default_discount_account").get_query = function(doc, cdt, cdn) {
|
||||
const row = locals[cdt][cdn];
|
||||
return {
|
||||
filters: {
|
||||
'report_type': 'Profit and Loss',
|
||||
'company': row.company,
|
||||
"is_group": 0
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
frm.fields_dict["item_defaults"].grid.get_field("buying_cost_center").get_query = function(doc, cdt, cdn) {
|
||||
const row = locals[cdt][cdn];
|
||||
return {
|
||||
|
@ -1067,7 +1067,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"links": [],
|
||||
"max_attachments": 1,
|
||||
"modified": "2021-03-18 14:04:38.575519",
|
||||
"modified": "2021-07-13 01:29:06.071827",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Stock",
|
||||
"name": "Item",
|
||||
@ -1138,4 +1138,4 @@
|
||||
"sort_order": "DESC",
|
||||
"title_field": "item_name",
|
||||
"track_changes": 1
|
||||
}
|
||||
}
|
@ -1,464 +1,118 @@
|
||||
{
|
||||
"allow_copy": 0,
|
||||
"allow_events_in_timeline": 0,
|
||||
"allow_guest_to_view": 0,
|
||||
"allow_import": 0,
|
||||
"allow_rename": 0,
|
||||
"beta": 0,
|
||||
"creation": "2018-05-03 02:29:24.444341",
|
||||
"custom": 0,
|
||||
"docstatus": 0,
|
||||
"doctype": "DocType",
|
||||
"document_type": "",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"actions": [],
|
||||
"creation": "2018-05-03 02:29:24.444341",
|
||||
"doctype": "DocType",
|
||||
"editable_grid": 1,
|
||||
"engine": "InnoDB",
|
||||
"field_order": [
|
||||
"company",
|
||||
"default_warehouse",
|
||||
"column_break_3",
|
||||
"default_price_list",
|
||||
"default_discount_account",
|
||||
"purchase_defaults",
|
||||
"buying_cost_center",
|
||||
"default_supplier",
|
||||
"column_break_8",
|
||||
"expense_account",
|
||||
"selling_defaults",
|
||||
"selling_cost_center",
|
||||
"column_break_12",
|
||||
"income_account"
|
||||
],
|
||||
"fields": [
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "company",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 1,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Company",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Company",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 1,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "company",
|
||||
"fieldtype": "Link",
|
||||
"ignore_user_permissions": 1,
|
||||
"in_list_view": 1,
|
||||
"label": "Company",
|
||||
"options": "Company",
|
||||
"reqd": 1
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "default_warehouse",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Default Warehouse",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Warehouse",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "default_warehouse",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Default Warehouse",
|
||||
"options": "Warehouse"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "column_break_3",
|
||||
"fieldtype": "Column Break",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "column_break_3",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "default_price_list",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 1,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Default Price List",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Price List",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "default_price_list",
|
||||
"fieldtype": "Link",
|
||||
"in_list_view": 1,
|
||||
"label": "Default Price List",
|
||||
"options": "Price List"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "purchase_defaults",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Purchase Defaults",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "purchase_defaults",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Purchase Defaults"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "buying_cost_center",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Default Buying Cost Center",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Cost Center",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "buying_cost_center",
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Buying Cost Center",
|
||||
"options": "Cost Center"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "default_supplier",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Default Supplier",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Supplier",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "default_supplier",
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Supplier",
|
||||
"options": "Supplier"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "column_break_8",
|
||||
"fieldtype": "Column Break",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "column_break_8",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "expense_account",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Default Expense Account",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Account",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "expense_account",
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Expense Account",
|
||||
"options": "Account"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "selling_defaults",
|
||||
"fieldtype": "Section Break",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Sales Defaults",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "selling_defaults",
|
||||
"fieldtype": "Section Break",
|
||||
"label": "Sales Defaults"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "selling_cost_center",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Default Selling Cost Center",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Cost Center",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "selling_cost_center",
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Selling Cost Center",
|
||||
"options": "Cost Center"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "column_break_12",
|
||||
"fieldtype": "Column Break",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
},
|
||||
"fieldname": "column_break_12",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"allow_bulk_edit": 0,
|
||||
"allow_in_quick_entry": 0,
|
||||
"allow_on_submit": 0,
|
||||
"bold": 0,
|
||||
"collapsible": 0,
|
||||
"columns": 0,
|
||||
"fieldname": "income_account",
|
||||
"fieldtype": "Link",
|
||||
"hidden": 0,
|
||||
"ignore_user_permissions": 0,
|
||||
"ignore_xss_filter": 0,
|
||||
"in_filter": 0,
|
||||
"in_global_search": 0,
|
||||
"in_list_view": 0,
|
||||
"in_standard_filter": 0,
|
||||
"label": "Default Income Account",
|
||||
"length": 0,
|
||||
"no_copy": 0,
|
||||
"options": "Account",
|
||||
"permlevel": 0,
|
||||
"precision": "",
|
||||
"print_hide": 0,
|
||||
"print_hide_if_no_value": 0,
|
||||
"read_only": 0,
|
||||
"remember_last_selected_value": 0,
|
||||
"report_hide": 0,
|
||||
"reqd": 0,
|
||||
"search_index": 0,
|
||||
"set_only_once": 0,
|
||||
"translatable": 0,
|
||||
"unique": 0
|
||||
"fieldname": "income_account",
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Income Account",
|
||||
"options": "Account"
|
||||
},
|
||||
{
|
||||
"fieldname": "default_discount_account",
|
||||
"fieldtype": "Link",
|
||||
"label": "Default Discount Account",
|
||||
"options": "Account"
|
||||
}
|
||||
],
|
||||
"has_web_view": 0,
|
||||
"hide_heading": 0,
|
||||
"hide_toolbar": 0,
|
||||
"idx": 0,
|
||||
"image_view": 0,
|
||||
"in_create": 0,
|
||||
"is_submittable": 0,
|
||||
"issingle": 0,
|
||||
"istable": 1,
|
||||
"max_attachments": 0,
|
||||
"modified": "2018-12-07 11:48:07.638935",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Stock",
|
||||
"name": "Item Default",
|
||||
"name_case": "",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"quick_entry": 1,
|
||||
"read_only": 0,
|
||||
"read_only_onload": 0,
|
||||
"show_name_in_global_search": 0,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1,
|
||||
"track_seen": 0,
|
||||
"track_views": 0
|
||||
],
|
||||
"istable": 1,
|
||||
"links": [],
|
||||
"modified": "2021-07-13 01:26:03.860065",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Stock",
|
||||
"name": "Item Default",
|
||||
"owner": "Administrator",
|
||||
"permissions": [],
|
||||
"quick_entry": 1,
|
||||
"sort_field": "modified",
|
||||
"sort_order": "DESC",
|
||||
"track_changes": 1
|
||||
}
|
@ -11,6 +11,7 @@ from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt \
|
||||
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
|
||||
from erpnext.accounts.doctype.account.test_account import get_inventory_account
|
||||
from erpnext.accounts.doctype.account.test_account import create_account
|
||||
from erpnext.assets.doctype.asset.test_asset import create_asset_category, create_fixed_asset_item
|
||||
|
||||
class TestLandedCostVoucher(unittest.TestCase):
|
||||
def test_landed_cost_voucher(self):
|
||||
@ -250,6 +251,39 @@ class TestLandedCostVoucher(unittest.TestCase):
|
||||
self.assertEqual(entry.credit, amounts[0])
|
||||
self.assertEqual(entry.credit_in_account_currency, amounts[1])
|
||||
|
||||
def test_asset_lcv(self):
|
||||
"Check if LCV for an Asset updates the Assets Gross Purchase Amount correctly."
|
||||
frappe.db.set_value("Company", "_Test Company", "capital_work_in_progress_account", "CWIP Account - _TC")
|
||||
|
||||
if not frappe.db.exists("Asset Category", "Computers"):
|
||||
create_asset_category()
|
||||
|
||||
if not frappe.db.exists("Item", "Macbook Pro"):
|
||||
create_fixed_asset_item()
|
||||
|
||||
pr = make_purchase_receipt(item_code="Macbook Pro", qty=1, rate=50000)
|
||||
|
||||
# check if draft asset was created
|
||||
assets = frappe.db.get_all('Asset', filters={'purchase_receipt': pr.name})
|
||||
self.assertEqual(len(assets), 1)
|
||||
|
||||
lcv = make_landed_cost_voucher(
|
||||
company = pr.company,
|
||||
receipt_document_type = "Purchase Receipt",
|
||||
receipt_document=pr.name,
|
||||
charges=80,
|
||||
expense_account="Expenses Included In Valuation - _TC")
|
||||
|
||||
lcv.save()
|
||||
lcv.submit()
|
||||
|
||||
# lcv updates amount in draft asset
|
||||
self.assertEqual(frappe.db.get_value("Asset", assets[0].name, "gross_purchase_amount"), 50080)
|
||||
|
||||
# tear down
|
||||
lcv.cancel()
|
||||
pr.cancel()
|
||||
|
||||
def make_landed_cost_voucher(** args):
|
||||
args = frappe._dict(args)
|
||||
ref_doc = frappe.get_doc(args.receipt_document_type, args.receipt_document)
|
||||
@ -268,7 +302,7 @@ def make_landed_cost_voucher(** args):
|
||||
|
||||
lcv.set("taxes", [{
|
||||
"description": "Shipping Charges",
|
||||
"expense_account": "Expenses Included In Valuation - TCP1",
|
||||
"expense_account": args.expense_account or "Expenses Included In Valuation - TCP1",
|
||||
"amount": args.charges
|
||||
}])
|
||||
|
||||
|
@ -162,8 +162,15 @@ class MaterialRequest(BuyingController):
|
||||
from `tabStock Entry Detail` where material_request = %s
|
||||
and material_request_item = %s and docstatus = 1""",
|
||||
(self.name, d.name))[0][0])
|
||||
mr_qty_allowance = frappe.db.get_single_value('Stock Settings', 'mr_qty_allowance')
|
||||
|
||||
if d.ordered_qty and d.ordered_qty > d.stock_qty:
|
||||
if mr_qty_allowance:
|
||||
allowed_qty = d.qty + (d.qty * (mr_qty_allowance/100))
|
||||
if d.ordered_qty and d.ordered_qty > allowed_qty:
|
||||
frappe.throw(_("The total Issue / Transfer quantity {0} in Material Request {1} \
|
||||
cannot be greater than allowed requested quantity {2} for Item {3}").format(d.ordered_qty, d.parent, allowed_qty, d.item_code))
|
||||
|
||||
elif d.ordered_qty and d.ordered_qty > d.stock_qty:
|
||||
frappe.throw(_("The total Issue / Transfer quantity {0} in Material Request {1} \
|
||||
cannot be greater than requested quantity {2} for Item {3}").format(d.ordered_qty, d.parent, d.qty, d.item_code))
|
||||
|
||||
|
@ -329,6 +329,58 @@ class TestMaterialRequest(unittest.TestCase):
|
||||
self.assertEqual(current_requested_qty_item1, existing_requested_qty_item1 + 54.0)
|
||||
self.assertEqual(current_requested_qty_item2, existing_requested_qty_item2 + 3.0)
|
||||
|
||||
def test_over_transfer_qty_allowance(self):
|
||||
mr = frappe.new_doc('Material Request')
|
||||
mr.company = "_Test Company"
|
||||
mr.scheduled_date = today()
|
||||
mr.append('items',{
|
||||
"item_code": "_Test FG Item",
|
||||
"item_name": "_Test FG Item",
|
||||
"qty": 10,
|
||||
"schedule_date": today(),
|
||||
"uom": "_Test UOM 1",
|
||||
"warehouse": "_Test Warehouse - _TC"
|
||||
})
|
||||
|
||||
mr.material_request_type = "Material Transfer"
|
||||
mr.insert()
|
||||
mr.submit()
|
||||
|
||||
frappe.db.set_value('Stock Settings', None, 'mr_qty_allowance', 20)
|
||||
|
||||
# map a stock entry
|
||||
|
||||
se_doc = make_stock_entry(mr.name)
|
||||
se_doc.update({
|
||||
"posting_date": today(),
|
||||
"posting_time": "00:00",
|
||||
})
|
||||
se_doc.get("items")[0].update({
|
||||
"qty": 13,
|
||||
"transfer_qty": 12.0,
|
||||
"s_warehouse": "_Test Warehouse - _TC",
|
||||
"t_warehouse": "_Test Warehouse 1 - _TC",
|
||||
"basic_rate": 1.0
|
||||
})
|
||||
|
||||
# make available the qty in _Test Warehouse 1 before transfer
|
||||
sr = frappe.new_doc("Stock Reconciliation")
|
||||
sr.company = "_Test Company"
|
||||
sr.purpose = "Opening Stock"
|
||||
sr.append('items', {
|
||||
"item_code": "_Test FG Item",
|
||||
"warehouse": "_Test Warehouse - _TC",
|
||||
"qty": 20,
|
||||
"valuation_rate": 0.01
|
||||
})
|
||||
sr.insert()
|
||||
sr.submit()
|
||||
se = frappe.copy_doc(se_doc)
|
||||
se.insert()
|
||||
self.assertRaises(frappe.ValidationError)
|
||||
se.items[0].qty = 12
|
||||
se.submit()
|
||||
|
||||
def test_completed_qty_for_over_transfer(self):
|
||||
existing_requested_qty_item1 = self._get_requested_qty("_Test Item Home Desktop 100", "_Test Warehouse - _TC")
|
||||
existing_requested_qty_item2 = self._get_requested_qty("_Test Item Home Desktop 200", "_Test Warehouse - _TC")
|
||||
|
@ -286,8 +286,16 @@ class PurchaseReceipt(BuyingController):
|
||||
and warehouse_account_name == supplier_warehouse_account:
|
||||
continue
|
||||
|
||||
self.add_gl_entry(gl_entries, warehouse_account_name, d.cost_center, stock_value_diff, 0.0, remarks,
|
||||
stock_rbnb, account_currency=warehouse_account_currency, item=d)
|
||||
self.add_gl_entry(
|
||||
gl_entries=gl_entries,
|
||||
account=warehouse_account_name,
|
||||
cost_center=d.cost_center,
|
||||
debit=stock_value_diff,
|
||||
credit=0.0,
|
||||
remarks=remarks,
|
||||
against_account=stock_rbnb,
|
||||
account_currency=warehouse_account_currency,
|
||||
item=d)
|
||||
|
||||
# GL Entry for from warehouse or Stock Received but not billed
|
||||
# Intentionally passed negative debit amount to avoid incorrect GL Entry validation
|
||||
@ -300,9 +308,17 @@ class PurchaseReceipt(BuyingController):
|
||||
account = warehouse_account[d.from_warehouse]['account'] \
|
||||
if d.from_warehouse else stock_rbnb
|
||||
|
||||
self.add_gl_entry(gl_entries, account, d.cost_center,
|
||||
-1 * flt(d.base_net_amount, d.precision("base_net_amount")), 0.0, remarks, warehouse_account_name,
|
||||
debit_in_account_currency=-1 * credit_amount, account_currency=credit_currency, item=d)
|
||||
self.add_gl_entry(
|
||||
gl_entries=gl_entries,
|
||||
account=account,
|
||||
cost_center=d.cost_center,
|
||||
debit=-1 * flt(d.base_net_amount, d.precision("base_net_amount")),
|
||||
credit=0.0,
|
||||
remarks=remarks,
|
||||
against_account=warehouse_account_name,
|
||||
debit_in_account_currency=-1 * credit_amount,
|
||||
account_currency=credit_currency,
|
||||
item=d)
|
||||
|
||||
# Amount added through landed-cos-voucher
|
||||
if d.landed_cost_voucher_amount and landed_cost_entries:
|
||||
@ -311,14 +327,31 @@ class PurchaseReceipt(BuyingController):
|
||||
credit_amount = (flt(amount["base_amount"]) if (amount["base_amount"] or
|
||||
account_currency!=self.company_currency) else flt(amount["amount"]))
|
||||
|
||||
self.add_gl_entry(gl_entries, account, d.cost_center, 0.0, credit_amount, remarks,
|
||||
warehouse_account_name, credit_in_account_currency=flt(amount["amount"]),
|
||||
account_currency=account_currency, project=d.project, item=d)
|
||||
self.add_gl_entry(
|
||||
gl_entries=gl_entries,
|
||||
account=account,
|
||||
cost_center=d.cost_center,
|
||||
debit=0.0,
|
||||
credit=credit_amount,
|
||||
remarks=remarks,
|
||||
against_account=warehouse_account_name,
|
||||
credit_in_account_currency=flt(amount["amount"]),
|
||||
account_currency=account_currency,
|
||||
project=d.project,
|
||||
item=d)
|
||||
|
||||
# sub-contracting warehouse
|
||||
if flt(d.rm_supp_cost) and warehouse_account.get(self.supplier_warehouse):
|
||||
self.add_gl_entry(gl_entries, supplier_warehouse_account, d.cost_center, 0.0, flt(d.rm_supp_cost),
|
||||
remarks, warehouse_account_name, account_currency=supplier_warehouse_account_currency, item=d)
|
||||
self.add_gl_entry(
|
||||
gl_entries=gl_entries,
|
||||
account=supplier_warehouse_account,
|
||||
cost_center=d.cost_center,
|
||||
debit=0.0,
|
||||
credit=flt(d.rm_supp_cost),
|
||||
remarks=remarks,
|
||||
against_account=warehouse_account_name,
|
||||
account_currency=supplier_warehouse_account_currency,
|
||||
item=d)
|
||||
|
||||
# divisional loss adjustment
|
||||
valuation_amount_as_per_doc = flt(d.base_net_amount, d.precision("base_net_amount")) + \
|
||||
@ -335,8 +368,17 @@ class PurchaseReceipt(BuyingController):
|
||||
|
||||
cost_center = d.cost_center or frappe.get_cached_value("Company", self.company, "cost_center")
|
||||
|
||||
self.add_gl_entry(gl_entries, loss_account, cost_center, divisional_loss, 0.0, remarks,
|
||||
warehouse_account_name, account_currency=credit_currency, project=d.project, item=d)
|
||||
self.add_gl_entry(
|
||||
gl_entries=gl_entries,
|
||||
account=loss_account,
|
||||
cost_center=cost_center,
|
||||
debit=divisional_loss,
|
||||
credit=0.0,
|
||||
remarks=remarks,
|
||||
against_account=warehouse_account_name,
|
||||
account_currency=credit_currency,
|
||||
project=d.project,
|
||||
item=d)
|
||||
|
||||
elif d.warehouse not in warehouse_with_no_account or \
|
||||
d.rejected_warehouse not in warehouse_with_no_account:
|
||||
@ -347,12 +389,30 @@ class PurchaseReceipt(BuyingController):
|
||||
debit_currency = get_account_currency(d.expense_account)
|
||||
remarks = self.get("remarks") or _("Accounting Entry for Service")
|
||||
|
||||
self.add_gl_entry(gl_entries, service_received_but_not_billed_account, d.cost_center, 0.0, d.amount,
|
||||
remarks, d.expense_account, account_currency=credit_currency, project=d.project,
|
||||
self.add_gl_entry(
|
||||
gl_entries=gl_entries,
|
||||
account=service_received_but_not_billed_account,
|
||||
cost_center=d.cost_center,
|
||||
debit=0.0,
|
||||
credit=d.amount,
|
||||
remarks=remarks,
|
||||
against_account=d.expense_account,
|
||||
account_currency=credit_currency,
|
||||
project=d.project,
|
||||
voucher_detail_no=d.name, item=d)
|
||||
|
||||
self.add_gl_entry(gl_entries, d.expense_account, d.cost_center, d.amount, 0.0, remarks, service_received_but_not_billed_account,
|
||||
account_currency = debit_currency, project=d.project, voucher_detail_no=d.name, item=d)
|
||||
self.add_gl_entry(
|
||||
gl_entries=gl_entries,
|
||||
account=d.expense_account,
|
||||
cost_center=d.cost_center,
|
||||
debit=d.amount,
|
||||
credit=0.0,
|
||||
remarks=remarks,
|
||||
against_account=service_received_but_not_billed_account,
|
||||
account_currency = debit_currency,
|
||||
project=d.project,
|
||||
voucher_detail_no=d.name,
|
||||
item=d)
|
||||
|
||||
if warehouse_with_no_account:
|
||||
frappe.msgprint(_("No accounting entries for the following warehouses") + ": \n" +
|
||||
@ -402,8 +462,15 @@ class PurchaseReceipt(BuyingController):
|
||||
applicable_amount = negative_expense_to_be_booked * (valuation_tax[tax.name] / total_valuation_amount)
|
||||
amount_including_divisional_loss -= applicable_amount
|
||||
|
||||
self.add_gl_entry(gl_entries, account, tax.cost_center, 0.0, applicable_amount, self.remarks or _("Accounting Entry for Stock"),
|
||||
against_account, item=tax)
|
||||
self.add_gl_entry(
|
||||
gl_entries=gl_entries,
|
||||
account=account,
|
||||
cost_center=tax.cost_center,
|
||||
debit=0.0,
|
||||
credit=applicable_amount,
|
||||
remarks=self.remarks or _("Accounting Entry for Stock"),
|
||||
against_account=against_account,
|
||||
item=tax)
|
||||
|
||||
i += 1
|
||||
|
||||
@ -456,15 +523,31 @@ class PurchaseReceipt(BuyingController):
|
||||
# debit cwip account
|
||||
debit_in_account_currency = (base_asset_amount
|
||||
if cwip_account_currency == self.company_currency else asset_amount)
|
||||
self.add_gl_entry(gl_entries, cwip_account, item.cost_center, base_asset_amount, 0.0, remarks,
|
||||
arbnb_account, debit_in_account_currency=debit_in_account_currency, item=item)
|
||||
self.add_gl_entry(
|
||||
gl_entries=gl_entries,
|
||||
account=cwip_account,
|
||||
cost_center=item.cost_center,
|
||||
debit=base_asset_amount,
|
||||
credit=0.0,
|
||||
remarks=remarks,
|
||||
against_account=arbnb_account,
|
||||
debit_in_account_currency=debit_in_account_currency,
|
||||
item=item)
|
||||
|
||||
asset_rbnb_currency = get_account_currency(arbnb_account)
|
||||
# credit arbnb account
|
||||
credit_in_account_currency = (base_asset_amount
|
||||
if asset_rbnb_currency == self.company_currency else asset_amount)
|
||||
self.add_gl_entry(gl_entries, arbnb_account, item.cost_center, 0.0, base_asset_amount, remarks,
|
||||
cwip_account, credit_in_account_currency=credit_in_account_currency, item=item)
|
||||
self.add_gl_entry(
|
||||
gl_entries=gl_entries,
|
||||
account=arbnb_account,
|
||||
cost_center=item.cost_center,
|
||||
debit=0.0,
|
||||
credit=base_asset_amount,
|
||||
remarks=remarks,
|
||||
against_account=cwip_account,
|
||||
credit_in_account_currency=credit_in_account_currency,
|
||||
item=item)
|
||||
|
||||
def add_lcv_gl_entries(self, item, gl_entries):
|
||||
expenses_included_in_asset_valuation = self.get_company_default("expenses_included_in_asset_valuation")
|
||||
@ -477,11 +560,27 @@ class PurchaseReceipt(BuyingController):
|
||||
|
||||
remarks = self.get("remarks") or _("Accounting Entry for Stock")
|
||||
|
||||
self.add_gl_entry(gl_entries, expenses_included_in_asset_valuation, item.cost_center, 0.0, flt(item.landed_cost_voucher_amount),
|
||||
remarks, asset_account, project=item.project, item=item)
|
||||
self.add_gl_entry(
|
||||
gl_entries=gl_entries,
|
||||
account=expenses_included_in_asset_valuation,
|
||||
cost_center=item.cost_center,
|
||||
debit=0.0,
|
||||
credit=flt(item.landed_cost_voucher_amount),
|
||||
remarks=remarks,
|
||||
against_account=asset_account,
|
||||
project=item.project,
|
||||
item=item)
|
||||
|
||||
self.add_gl_entry(gl_entries, asset_account, item.cost_center, 0.0, flt(item.landed_cost_voucher_amount),
|
||||
remarks, expenses_included_in_asset_valuation, project=item.project, item=item)
|
||||
self.add_gl_entry(
|
||||
gl_entries=gl_entries,
|
||||
account=asset_account,
|
||||
cost_center=item.cost_center,
|
||||
debit=flt(item.landed_cost_voucher_amount),
|
||||
credit=0.0,
|
||||
remarks=remarks,
|
||||
against_account=expenses_included_in_asset_valuation,
|
||||
project=item.project,
|
||||
item=item)
|
||||
|
||||
def update_assets(self, item, valuation_rate):
|
||||
assets = frappe.db.get_all('Asset',
|
||||
@ -598,6 +697,7 @@ def make_purchase_invoice(source_name, target_doc=None):
|
||||
doc.run_method("onload")
|
||||
doc.run_method("set_missing_values")
|
||||
doc.run_method("calculate_taxes_and_totals")
|
||||
doc.set_payment_schedule()
|
||||
|
||||
def update_item(source_doc, target_doc, source_parent):
|
||||
target_doc.qty, returned_qty = get_pending_qty(source_doc)
|
||||
|
@ -1037,6 +1037,33 @@ class TestPurchaseReceipt(unittest.TestCase):
|
||||
|
||||
frappe.db.set_value('Company', company, 'enable_perpetual_inventory_for_non_stock_items', before_test_value)
|
||||
|
||||
def test_payment_terms_are_fetched_when_creating_purchase_invoice(self):
|
||||
from erpnext.accounts.doctype.payment_entry.test_payment_entry import create_payment_terms_template
|
||||
from erpnext.accounts.doctype.purchase_invoice.test_purchase_invoice import make_purchase_invoice
|
||||
from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order, make_pr_against_po
|
||||
from erpnext.selling.doctype.sales_order.test_sales_order import automatically_fetch_payment_terms, compare_payment_schedules
|
||||
|
||||
automatically_fetch_payment_terms()
|
||||
|
||||
po = create_purchase_order(qty=10, rate=100, do_not_save=1)
|
||||
create_payment_terms_template()
|
||||
po.payment_terms_template = 'Test Receivable Template'
|
||||
po.submit()
|
||||
|
||||
pr = make_pr_against_po(po.name, received_qty=10)
|
||||
|
||||
pi = make_purchase_invoice(qty=10, rate=100, do_not_save=1)
|
||||
pi.items[0].purchase_receipt = pr.name
|
||||
pi.items[0].pr_detail = pr.items[0].name
|
||||
pi.items[0].purchase_order = po.name
|
||||
pi.items[0].po_detail = po.items[0].name
|
||||
pi.insert()
|
||||
|
||||
# self.assertEqual(po.payment_terms_template, pi.payment_terms_template)
|
||||
compare_payment_schedules(self, po, pi)
|
||||
|
||||
automatically_fetch_payment_terms(enable=0)
|
||||
|
||||
def get_sl_entries(voucher_type, voucher_no):
|
||||
return frappe.db.sql(""" select actual_qty, warehouse, stock_value_difference
|
||||
from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s
|
||||
|
@ -165,8 +165,14 @@ class SerialNo(StockController):
|
||||
)
|
||||
ORDER BY
|
||||
posting_date desc, posting_time desc, creation desc""",
|
||||
(self.item_code, self.company,
|
||||
serial_no, serial_no+'\n%', '%\n'+serial_no, '%\n'+serial_no+'\n%'), as_dict=1):
|
||||
(
|
||||
self.item_code, self.company,
|
||||
serial_no,
|
||||
serial_no+'\n%',
|
||||
'%\n'+serial_no,
|
||||
'%\n'+serial_no+'\n%'
|
||||
),
|
||||
as_dict=1):
|
||||
if serial_no.upper() in get_serial_nos(sle.serial_no):
|
||||
if cint(sle.actual_qty) > 0:
|
||||
sle_dict.setdefault("incoming", []).append(sle)
|
||||
|
@ -174,5 +174,23 @@ class TestSerialNo(unittest.TestCase):
|
||||
self.assertEqual(sn_doc.warehouse, "_Test Warehouse - _TC")
|
||||
self.assertEqual(sn_doc.purchase_document_no, se.name)
|
||||
|
||||
def test_serial_no_sanitation(self):
|
||||
"Test if Serial No input is sanitised before entering the DB."
|
||||
item_code = "_Test Serialized Item"
|
||||
test_records = frappe.get_test_records('Stock Entry')
|
||||
|
||||
se = frappe.copy_doc(test_records[0])
|
||||
se.get("items")[0].item_code = item_code
|
||||
se.get("items")[0].qty = 3
|
||||
se.get("items")[0].serial_no = " _TS1, _TS2 , _TS3 "
|
||||
se.get("items")[0].transfer_qty = 3
|
||||
se.set_stock_entry_type()
|
||||
se.insert()
|
||||
se.submit()
|
||||
|
||||
self.assertEqual(se.get("items")[0].serial_no, "_TS1\n_TS2\n_TS3")
|
||||
|
||||
frappe.db.rollback()
|
||||
|
||||
def tearDown(self):
|
||||
frappe.db.rollback()
|
@ -76,6 +76,7 @@ class StockEntry(StockController):
|
||||
self.validate_difference_account()
|
||||
self.set_job_card_data()
|
||||
self.set_purpose_for_stock_entry()
|
||||
self.clean_serial_nos()
|
||||
self.validate_duplicate_serial_no()
|
||||
|
||||
if not self.from_bom:
|
||||
|
@ -31,6 +31,7 @@ class StockReconciliation(StockController):
|
||||
self.validate_expense_account()
|
||||
self.validate_customer_provided_item()
|
||||
self.set_zero_value_for_customer_provided_items()
|
||||
self.clean_serial_nos()
|
||||
self.set_total_qty_and_amount()
|
||||
self.validate_putaway_capacity()
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
"section_break_9",
|
||||
"over_delivery_receipt_allowance",
|
||||
"role_allowed_to_over_deliver_receive",
|
||||
"mr_qty_allowance",
|
||||
"column_break_12",
|
||||
"auto_insert_price_list_rate_if_missing",
|
||||
"allow_negative_stock",
|
||||
@ -283,6 +284,12 @@
|
||||
"fieldtype": "Select",
|
||||
"label": "Action If Quality Inspection Is Rejected",
|
||||
"options": "Stop\nWarn"
|
||||
},
|
||||
{
|
||||
"description": "The percentage you are allowed to transfer more against the quantity ordered. For example, if you have ordered 100 units, and your Allowance is 10%, then you are allowed transfer 110 units.",
|
||||
"fieldname": "mr_qty_allowance",
|
||||
"fieldtype": "Float",
|
||||
"label": "Over Transfer Allowance"
|
||||
}
|
||||
],
|
||||
"icon": "icon-cog",
|
||||
@ -290,7 +297,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2021-07-10 16:17:42.159829",
|
||||
"modified": "2021-06-28 17:02:26.683002",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Stock",
|
||||
"name": "Stock Settings",
|
||||
@ -310,4 +317,4 @@
|
||||
"sort_field": "modified",
|
||||
"sort_order": "ASC",
|
||||
"track_changes": 1
|
||||
}
|
||||
}
|
||||
|
@ -286,6 +286,7 @@ def get_basic_details(args, item, overwrite_warehouse=True):
|
||||
"warehouse": warehouse,
|
||||
"income_account": get_default_income_account(args, item_defaults, item_group_defaults, brand_defaults),
|
||||
"expense_account": expense_account or get_default_expense_account(args, item_defaults, item_group_defaults, brand_defaults) ,
|
||||
"discount_account": None or get_default_discount_account(args, item_defaults),
|
||||
"cost_center": get_default_cost_center(args, item_defaults, item_group_defaults, brand_defaults),
|
||||
'has_serial_no': item.has_serial_no,
|
||||
'has_batch_no': item.has_batch_no,
|
||||
@ -588,6 +589,10 @@ def get_default_expense_account(args, item, item_group, brand):
|
||||
or brand.get("expense_account")
|
||||
or args.expense_account)
|
||||
|
||||
def get_default_discount_account(args, item):
|
||||
return (item.get("default_discount_account")
|
||||
or args.discount_account)
|
||||
|
||||
def get_default_deferred_account(args, item, fieldname=None):
|
||||
if item.get("enable_deferred_revenue") or item.get("enable_deferred_expense"):
|
||||
return (item.get(fieldname)
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user