I need to change amount calculation for each item in sales invoice to be:
amount = rate * qty * custom_field
I tried this, but it doesn't work.
frappe.ui.form.on("Sales Invoice Item", "custom_field", (frm, cdt, cdn) => {
var d = locals[cdt][cdn];
frappe.model.set_value("amount", d.qty*d.custom_field*d.rate) ;
});
Set value should be used like
frappe.model.set_value(DOC_TYPE, DOC_NAME, FIELD_NAME, NEW_VALUE);
So, in your case
frappe.model.set_value("Sales Invoice Item", cdn, "amount", d.qty*d.custom_field*d.rate);
Or
frappe.model.set_value(cdt, cdn, "amount", d.qty*d.custom_field*d.rate);
Related
I created a Form for requesting new student Google account. I want a Sheets Script to email the person who submits the Form the new account information, which is created via a formula on a "Results" sheet.
function Notification() {
// Send email notice for accounts
var lastRow = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Results").getLastRow();
var range = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Results").getRange("A" + lastRow);
if (range.getValue() !== "") {
return lastRow;
} else {
return range.getNextDataCell(SpreadsheetApp.Direction.UP).getRow();
var AccountName = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Results").getRange("H" + lastRow);
var Password = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Results").getRange("I" + lastRow);
var PW = Password.getValue();
var Account = AccountName.getValue();
// Fetch the email address
var emailRange = SpreadsheetApp.getActiveSpreadsheet().getSheetByName("Results").getRange("G" + lastRow);
var emailAddress = emailRange.getValues();
// Send Alert Email.
var message = 'Account Request - Account Name: ' + Account + ' Password: ' + PW; // Second column
var subject = 'Google Account Request';
MailApp.sendEmail(emailAddress, subject, message);
}
This script is triggered on a new Form Submit. Attempting to pull the values from the last created row queried to a "Results" sheet, using lastRow to find the latest entries row, from select columns. Script runs without error, but no email is sent, telling me that it's not getting the values, or returning null values.
This is the sheet its pulling data from
You are only sending row 2 because you are retrieving only one value (Password.getValue() and AccountName.getValue()). Consider the difference between getValue versus getValues.
On the other hand, by declaring a range such as getRange("H2:H") ("Account Name") you are including every row in the spreadsheet, including rows with and without content.
How would I make it pull the values from the last created row?
There are two options:
getlastRow() (the "Sheet" versus "Range" version) "returns the position of the last row that has content" doc ref here. In fact, that item of documentation has a good example of how to declare a Range using the command.
there is another (very useful) utility described on StackOverflow that is a favourite of mine. This describes the number of contiguous rows, in a column, with content.
I suggest that you declare the range using getRange(row, column, numRows, numColumns).
"row" having been determined using one of the methods described above, "numRows"=1. Then getValues for that range will include only the values in that row, and your email will be sent only in relation to that row.
I have three tables
SalesDetails with columns SalesId, ProductId, Qty, Price etc
SalesPersonDtls with columns SalesId, SalesPersonId, CommPercentage etc
SalesPerson with columns SalesPersonId, firstName, lastName etc
I have second table because one sale can be done by more than one sales person together with split commission.
I have various inputs in search screen like productname, sales date, sales person name etc.
I am making the model class as 'AsQueryable' and add various where conditions and finally the result into a list.
I have sales person's name in search criteria but I don't know how to include this into the search. Can you please help?
Thanks
Peter
Peter
If I get it correct , relation of your business models is like this :
person (n) <-----> (1) Sale (1) <-----> (n) Details
you put sale and person relation in "SalesPersonDtls" and sale and detail relation to "SalesDetails". I think it's better to change your entities a little bit, if you want to get better result as your project getting bigger and more complex.
Your entities should be like this :
Sale
{
List<SalesDetail> details;
List<Person> persons;
...
}
SalesDetail
{
Sale
...
}
Person
{
Sale
name
...
}
Now it's really simple , if you want sales that is related to a personName :
sales.Where(sale => sale.Persons.Any(person => person.PersonName == "your input name"));
UPDATE :
If you can't or don't want to change your models:
first you need to find personId by it'name and then search into your "SalesPersonDtls" and get saleIds.
I am completely new to the Python world, but I am trying to learn this beautiful language. But I need your help.
I have an API, and I want it when a user wants to change the value of any data about his product, and it is updated with the new value.
For example:
I have the following product:
Title = DC snowboard boots
Description = Hi everyone, I'm selling this snowboard boots and both
are brand new for £ 130
Price = £ 130
And then the user makes a request to change for example the price of the product.
And completely lost in how to do that.
My view for update the product:
import app.utils.responses as resp
from app.api import api
from app.database import db
from app.models.products import Products, ProductsSchema
from app.utils.responses import m_return
#api.route('/product/<product_id>', methods=['PATCH'])
def update_product(product_id):
# Get products data
product_to_update = Products.query.get(product_id)
Products.id = product_to_update
result = Products.id
db.session.merge(result)
db.session.commit()
# Products schema for some fields.
products_schema = ProductsSchema(
only=('id', 'title', 'description', 'post_code', 'product_name', 'is_available', 'created', 'price'))
# Return item updated.
return m_return(
http_code=resp.PRODUCT_UPDATED_SUCCESSFULLY['http_code'],
message=resp.PRODUCT_UPDATED_SUCCESSFULLY['message'],
value=products_schema.dump(result).data
)
product_to_update = Products.query.get(product_id)
This code returns a Products object if product_id is in db, if yes then you can update columns of this product:
product_to_update.price = 123#new price
db.session.commit()
So for this specific product the price will be update.
I've been unable to find an accurate answer for this.
As we know already, PayPal's REST API doesn't have a option for applying discount code. However, we can append another item to the item_list with a description of a I.e. Promo / Discount code.
So e.g. breaking this into human readable data, here's what I'm passing to the API.
Transaction
Amount: 100
item_list: [ product1, 60 ], [ product2, 60 ], [ coupon_code, -20 ]
Visually, This route should work (as it does in the classic API). However, the PayPal API doesn't allow negative numbers.
Ideally, we want to use the signed / OAuth route via PayPal REST API Vs. the open / classic API.
Update 1/13/2014
I noticed Storenvy has the ability to apply discounts to their connected user's PayPal accounts. However, If I recall Storenvy has a partnership with PayPal - I'm wondering if they're on a specific internal rest API version for the discount support?
I do it creating another item, and giving a negative price.
$item = new Item();
$price = -11.20;
......
$item->setName($name)
->setCurrency($currency)
->setQuantity($quantity)
->setSku($sku)
->setPrice($price);
For this example I have a Promo code of -11.20 euro:
What worked for me:
Add a discount field to the breakdown:
'discount' => [
'currency_code' => $order->currency,
'value' => $order->coupon_total,
]
See PayPal's docs: https://developer.paypal.com/docs/api/orders/v2/#definition-amount_breakdown
The discount will the show up as discount in the price breakdown.
Make negative value of coupon discount amount. It worked for me.
$itemArray = array();
if (isset($request->couponId)) {
// coupon object
$coupon = (new Promocodes())->check($request->couponId);
if (isset($coupon->code)) {
$item = new Item();
$item->setName('Coupon Discount')
->setCurrency('GBP')
->setQuantity(1)
->setPrice(($coupon->reward * (-1)));
// to reduce reward amount from total
$totalAmount -= $coupon->reward;
array_push($itemArray, $item);
}
}
For discount we do have the discount variables discount_amount and discount_percentage where you can get:
The amount and currency of the discount applied to the payment.
See the reference https://developer.paypal.com/docs/api/payments/ and search for the term "discount" there.
I hope this helps.
I'd like to build a dynamic FORM according to DB Table records.
It'a room reservation module.
Hotel has several room types with descriptions.
When booking a hotel user should see form like:
-- firstname [text-input]
-- lastname [text-input]
-- check-in [text-input and datepicker]
-- check-out [text-input and datepicker]
-- Room1 Title:Room Description [Text-input form for number of rooms]
-- Room2 Title:Room Description [Text-input form for number of rooms]
-- Room3 Title:Room Description [Text-input form for number of rooms]
-- Room4 Title:Room Description [Text-input form for number of rooms]
I have this Room records in a table.
How can I build this with ZEND_FORM?
I think it should be smth like foreach of objects of rooms
I also would like to add auto calculations.
Each room has specific price per night.
I want to sum-up number of rooms and multiply by number of nights.
So how can I accomplish it using Zend_Form?
Should I add some helpers? new type of text element?
If yes, please provide some sources to guide's and How To's with examples.
Thank you in advance.
I had something similar but with checkboxes, this is an adaptation, I hope it helps.
class Form_Booking extends Zend_Form {
function init()
{
$this->addElement('text', 'first_name', array (
'label' => 'First name',
'required' => true
));
// ... all the other fields
$count = 1000; // I used this value because I had a strange bug
//$rooms = array() the entries from your table
foreach ($rooms as $one)
{
$this->addElement('checkbox', "$count", array (
'label' => $one['room_title'],
'description' => $one['room_description'],
'belongsTo' => 'rooms',
));
$count++;
}
}
}